Skip to content

Commit b8a873c

Browse files
committed
Ensure mincore_call_threshold is decremented atomically
1 parent 557a6e7 commit b8a873c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/lib/lwan-mod-serve-files.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ struct mmap_cache_data {
117117
#if defined(LWAN_HAVE_ZSTD)
118118
struct lwan_value zstd;
119119
#endif
120-
int mincore_call_threshold;
120+
unsigned int mincore_call_threshold;
121121
};
122122

123123
struct sendfile_cache_data {
@@ -1260,9 +1260,11 @@ static enum lwan_http_status mmap_serve(struct lwan_request *request,
12601260
compression_hdr);
12611261

12621262
#ifdef LWAN_HAVE_MINCORE
1263-
if (md->mincore_call_threshold-- == 0) {
1263+
if (ATOMIC_DEC(md->mincore_call_threshold) == 0) {
12641264
unsigned char mincore_vec[MINCORE_VEC_LEN(MMAP_SIZE_THRESHOLD)];
12651265

1266+
md->mincore_call_threshold = MINCORE_CALL_THRESHOLD;
1267+
12661268
if (!mincore(to_serve->value, to_serve->len, mincore_vec)) {
12671269
const size_t pgs = MINCORE_VEC_LEN(to_serve->len);
12681270

@@ -1276,8 +1278,6 @@ static enum lwan_http_status mmap_serve(struct lwan_request *request,
12761278
break;
12771279
}
12781280
}
1279-
1280-
md->mincore_call_threshold = MINCORE_CALL_THRESHOLD;
12811281
}
12821282
#endif
12831283

0 commit comments

Comments
 (0)