| line |
true |
false |
branch |
|
83
|
0 |
3 |
if (dl->tv_nsec >= 1000000000L) { dl->tv_sec++; dl->tv_nsec -= 1000000000L; } |
|
91
|
3 |
2 |
if (rem->tv_nsec < 0) { rem->tv_sec--; rem->tv_nsec += 1000000000L; } |
|
107
|
3 |
40 |
if (t >= (uint32_t)hdr->capacity) return 0; |
|
108
|
40 |
0 |
if (__atomic_compare_exchange_n(&hdr->top, &t, t + 1, |
|
113
|
0 |
40 |
if (cp < sz) memset(stk_slot(h, t) + cp, 0, sz - cp); |
|
116
|
0 |
40 |
if (__atomic_load_n(&hdr->waiters_pop, __ATOMIC_RELAXED) > 0) |
|
124
|
0 |
1 |
if (stk_try_push(h, val, vlen)) return 1; |
|
125
|
0 |
1 |
if (timeout == 0) return 0; |
|
130
|
1 |
0 |
if (has_dl) stk_make_deadline(timeout, &dl); |
|
136
|
1 |
0 |
if (t >= (uint32_t)hdr->capacity) { |
|
138
|
1 |
0 |
if (has_dl) { |
|
139
|
0 |
1 |
if (!stk_remaining(&dl, &rem)) { |
|
149
|
0 |
1 |
if (stk_try_push(h, val, vlen)) return 1; |
|
150
|
1 |
0 |
if (has_dl && !stk_remaining(&dl, &rem)) { |
|
|
1 |
0 |
if (has_dl && !stk_remaining(&dl, &rem)) { |
|
165
|
6 |
21 |
if (t == 0) return 0; |
|
166
|
21 |
0 |
if (__atomic_compare_exchange_n(&hdr->top, &t, t - 1, |
|
174
|
0 |
21 |
if (__atomic_load_n(&hdr->waiters_push, __ATOMIC_RELAXED) > 0) |
|
182
|
0 |
2 |
if (stk_try_pop(h, out)) return 1; |
|
183
|
0 |
2 |
if (timeout == 0) return 0; |
|
188
|
2 |
0 |
if (has_dl) stk_make_deadline(timeout, &dl); |
|
194
|
2 |
0 |
if (t == 0) { |
|
196
|
2 |
0 |
if (has_dl) { |
|
197
|
0 |
2 |
if (!stk_remaining(&dl, &rem)) { |
|
207
|
1 |
1 |
if (stk_try_pop(h, out)) return 1; |
|
208
|
1 |
0 |
if (has_dl && !stk_remaining(&dl, &rem)) { |
|
|
1 |
0 |
if (has_dl && !stk_remaining(&dl, &rem)) { |
|
221
|
0 |
2 |
if (t == 0) return 0; |
|
255
|
0 |
10 |
if (!h) { munmap(base, msize); return NULL; } |
|
260
|
3 |
7 |
h->path = path ? strdup(path) : NULL; |
|
269
|
8 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
270
|
0 |
8 |
if (capacity == 0) { STK_ERR("capacity must be > 0"); return NULL; } |
|
|
0 |
0 |
if (capacity == 0) { STK_ERR("capacity must be > 0"); return NULL; } |
|
271
|
0 |
8 |
if (elem_size == 0) { STK_ERR("elem_size must be > 0"); return NULL; } |
|
|
0 |
0 |
if (elem_size == 0) { STK_ERR("elem_size must be > 0"); return NULL; } |
|
272
|
8 |
0 |
if (elem_size > 0 && capacity > (UINT64_MAX - sizeof(StkHeader)) / elem_size) { |
|
|
0 |
8 |
if (elem_size > 0 && capacity > (UINT64_MAX - sizeof(StkHeader)) / elem_size) { |
|
273
|
0 |
0 |
STK_ERR("capacity * elem_size overflow"); return NULL; |
|
282
|
5 |
3 |
if (anonymous) { |
|
286
|
0 |
5 |
if (base == MAP_FAILED) { STK_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { STK_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
289
|
0 |
3 |
if (fd < 0) { STK_ERR("open(%s): %s", path, strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (fd < 0) { STK_ERR("open(%s): %s", path, strerror(errno)); return NULL; } |
|
290
|
0 |
3 |
if (flock(fd, LOCK_EX) < 0) { STK_ERR("flock: %s", strerror(errno)); close(fd); return NULL; } |
|
|
0 |
0 |
if (flock(fd, LOCK_EX) < 0) { STK_ERR("flock: %s", strerror(errno)); close(fd); return NULL; } |
|
293
|
0 |
3 |
if (fstat(fd, &st) < 0) { |
|
294
|
0 |
0 |
STK_ERR("fstat: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; |
|
298
|
2 |
1 |
if (is_new) { |
|
299
|
0 |
2 |
if (ftruncate(fd, (off_t)total) < 0) { |
|
300
|
0 |
0 |
STK_ERR("ftruncate: %s", strerror(errno)); |
|
304
|
1 |
2 |
map_size = is_new ? (size_t)total : (size_t)st.st_size; |
|
306
|
0 |
3 |
if (base == MAP_FAILED) { STK_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { STK_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; } |
|
308
|
1 |
2 |
if (!is_new) { |
|
310
|
1 |
0 |
if (hdr->magic != STK_MAGIC || hdr->version != STK_VERSION || |
|
|
1 |
0 |
if (hdr->magic != STK_MAGIC || hdr->version != STK_VERSION || |
|
311
|
1 |
0 |
hdr->variant_id != variant_id || |
|
312
|
0 |
1 |
hdr->total_size != (uint64_t)st.st_size) { |
|
313
|
0 |
0 |
STK_ERR("invalid or incompatible stack file"); |
|
322
|
2 |
5 |
if (fd >= 0) { flock(fd, LOCK_UN); close(fd); } |
|
329
|
1 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
330
|
0 |
1 |
if (capacity == 0) { STK_ERR("capacity must be > 0"); return NULL; } |
|
|
0 |
0 |
if (capacity == 0) { STK_ERR("capacity must be > 0"); return NULL; } |
|
331
|
0 |
1 |
if (elem_size == 0) { STK_ERR("elem_size must be > 0"); return NULL; } |
|
|
0 |
0 |
if (elem_size == 0) { STK_ERR("elem_size must be > 0"); return NULL; } |
|
332
|
1 |
0 |
if (elem_size > 0 && capacity > (UINT64_MAX - sizeof(StkHeader)) / elem_size) { |
|
|
0 |
1 |
if (elem_size > 0 && capacity > (UINT64_MAX - sizeof(StkHeader)) / elem_size) { |
|
333
|
0 |
0 |
STK_ERR("capacity * elem_size overflow"); return NULL; |
|
337
|
1 |
0 |
int fd = memfd_create(name ? name : "stack", MFD_CLOEXEC); |
|
338
|
0 |
1 |
if (fd < 0) { STK_ERR("memfd_create: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (fd < 0) { STK_ERR("memfd_create: %s", strerror(errno)); return NULL; } |
|
339
|
0 |
1 |
if (ftruncate(fd, (off_t)total) < 0) { STK_ERR("ftruncate: %s", strerror(errno)); close(fd); return NULL; } |
|
|
0 |
0 |
if (ftruncate(fd, (off_t)total) < 0) { STK_ERR("ftruncate: %s", strerror(errno)); close(fd); return NULL; } |
|
341
|
0 |
1 |
if (base == MAP_FAILED) { STK_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { STK_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; } |
|
347
|
1 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
349
|
0 |
1 |
if (fstat(fd, &st) < 0) { STK_ERR("fstat: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (fstat(fd, &st) < 0) { STK_ERR("fstat: %s", strerror(errno)); return NULL; } |
|
350
|
0 |
1 |
if ((uint64_t)st.st_size < sizeof(StkHeader)) { STK_ERR("too small"); return NULL; } |
|
|
0 |
0 |
if ((uint64_t)st.st_size < sizeof(StkHeader)) { STK_ERR("too small"); return NULL; } |
|
353
|
0 |
1 |
if (base == MAP_FAILED) { STK_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { STK_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
355
|
1 |
0 |
if (hdr->magic != STK_MAGIC || hdr->version != STK_VERSION || |
|
|
1 |
0 |
if (hdr->magic != STK_MAGIC || hdr->version != STK_VERSION || |
|
356
|
1 |
0 |
hdr->variant_id != variant_id || |
|
357
|
0 |
1 |
hdr->total_size != (uint64_t)st.st_size) { |
|
358
|
0 |
0 |
STK_ERR("invalid stack"); munmap(base, ms); return NULL; |
|
361
|
0 |
1 |
if (myfd < 0) { STK_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; } |
|
|
0 |
0 |
if (myfd < 0) { STK_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; } |
|
366
|
0 |
10 |
if (!h) return; |
|
367
|
1 |
9 |
if (h->notify_fd >= 0) close(h->notify_fd); |
|
368
|
2 |
8 |
if (h->backing_fd >= 0) close(h->backing_fd); |
|
369
|
10 |
0 |
if (h->hdr) munmap(h->hdr, h->mmap_size); |
|
377
|
3 |
0 |
if (__atomic_load_n(&h->hdr->waiters_push, __ATOMIC_RELAXED) > 0 || |
|
378
|
0 |
3 |
__atomic_load_n(&h->hdr->waiters_pop, __ATOMIC_RELAXED) > 0) |
|
387
|
0 |
0 |
if (t == 0) return 0; |
|
388
|
0 |
0 |
if (__atomic_compare_exchange_n(&hdr->top, &t, 0, |
|
390
|
0 |
0 |
if (__atomic_load_n(&hdr->waiters_push, __ATOMIC_RELAXED) > 0) |
|
399
|
0 |
1 |
if (h->notify_fd >= 0) close(h->notify_fd); |
|
401
|
0 |
1 |
if (efd < 0) return -1; |
|
406
|
0 |
2 |
if (h->notify_fd < 0) return 0; |
|
411
|
0 |
1 |
if (h->notify_fd < 0) return -1; |
|
413
|
0 |
1 |
if (read(h->notify_fd, &v, sizeof(v)) != sizeof(v)) return -1; |