| line |
true |
false |
branch |
|
111
|
0 |
5 |
if (dl->tv_nsec >= 1000000000L) { dl->tv_sec++; dl->tv_nsec -= 1000000000L; } |
|
119
|
5 |
4 |
if (rem->tv_nsec < 0) { rem->tv_sec--; rem->tv_nsec += 1000000000L; } |
|
150
|
88 |
0 |
if (DEQ_SLOT_STATE(c) == DEQ_SLOT_EMPTY) { |
|
152
|
88 |
0 |
if (__atomic_compare_exchange_n(ctl_word, &c, nc, |
|
169
|
18057 |
0 |
if (DEQ_SLOT_STATE(c) == DEQ_SLOT_FILLED) { |
|
171
|
18057 |
0 |
if (__atomic_compare_exchange_n(ctl_word, &c, nc, |
|
194
|
5 |
78 |
if ((uint32_t)(t - hd) >= cap) return 0; |
|
196
|
78 |
0 |
if (__atomic_compare_exchange_n(&hdr->cursor, &c, nc, |
|
203
|
0 |
78 |
if (cp < sz) memset(deq_slot(h, t) + cp, 0, sz - cp); |
|
206
|
0 |
78 |
if (__atomic_load_n(&hdr->waiters_pop, __ATOMIC_RELAXED) > 0) { |
|
225
|
5 |
10 |
if ((uint32_t)(t - hd) >= cap) return 0; |
|
228
|
10 |
0 |
if (__atomic_compare_exchange_n(&hdr->cursor, &c, nc, |
|
235
|
0 |
10 |
if (cp < sz) memset(deq_slot(h, new_hd) + cp, 0, sz - cp); |
|
238
|
0 |
10 |
if (__atomic_load_n(&hdr->waiters_pop, __ATOMIC_RELAXED) > 0) { |
|
257
|
6 |
18042 |
if ((uint32_t)(t - hd) == 0) return 0; |
|
259
|
18042 |
0 |
if (__atomic_compare_exchange_n(&hdr->cursor, &c, nc, |
|
266
|
0 |
18042 |
if (__atomic_load_n(&hdr->waiters_push, __ATOMIC_RELAXED) > 0) { |
|
285
|
4 |
10 |
if ((uint32_t)(t - hd) == 0) return 0; |
|
287
|
10 |
0 |
if (__atomic_compare_exchange_n(&hdr->cursor, &c, nc, |
|
294
|
0 |
10 |
if (__atomic_load_n(&hdr->waiters_push, __ATOMIC_RELAXED) > 0) { |
|
310
|
1 |
1 |
front ? deq_try_push_front : deq_try_push_back; |
|
311
|
0 |
2 |
if (try_fn(h, val, vlen)) return 1; |
|
312
|
0 |
2 |
if (timeout == 0) return 0; |
|
317
|
2 |
0 |
if (has_dl) deq_make_deadline(timeout, &dl); |
|
325
|
2 |
0 |
if (DEQ_CURSOR_SIZE(c) >= cap) { |
|
327
|
2 |
0 |
if (has_dl) { |
|
328
|
0 |
2 |
if (!deq_remaining(&dl, &rem)) { |
|
338
|
0 |
2 |
if (try_fn(h, val, vlen)) return 1; |
|
339
|
2 |
0 |
if (has_dl && !deq_remaining(&dl, &rem)) { |
|
|
2 |
0 |
if (has_dl && !deq_remaining(&dl, &rem)) { |
|
348
|
1 |
2 |
back ? deq_try_pop_back : deq_try_pop_front; |
|
349
|
0 |
3 |
if (try_fn(h, out)) return 1; |
|
350
|
0 |
3 |
if (timeout == 0) return 0; |
|
355
|
3 |
0 |
if (has_dl) deq_make_deadline(timeout, &dl); |
|
362
|
3 |
0 |
if (DEQ_CURSOR_SIZE(c) == 0) { |
|
364
|
3 |
0 |
if (has_dl) { |
|
365
|
0 |
3 |
if (!deq_remaining(&dl, &rem)) { |
|
375
|
1 |
2 |
if (try_fn(h, out)) return 1; |
|
376
|
2 |
0 |
if (has_dl && !deq_remaining(&dl, &rem)) { |
|
|
2 |
0 |
if (has_dl && !deq_remaining(&dl, &rem)) { |
|
418
|
0 |
18 |
if (!h) { munmap(base, ms); return NULL; } |
|
424
|
5 |
13 |
h->path = path ? strdup(path) : NULL; |
|
433
|
1 |
3 |
if (hdr->magic != DEQ_MAGIC) return 0; |
|
434
|
0 |
3 |
if (hdr->version != DEQ_VERSION) return 0; |
|
435
|
0 |
3 |
if (hdr->variant_id != expected_variant) return 0; |
|
436
|
3 |
0 |
if (hdr->elem_size == 0 || hdr->capacity == 0) return 0; |
|
|
0 |
3 |
if (hdr->elem_size == 0 || hdr->capacity == 0) return 0; |
|
437
|
0 |
3 |
if (hdr->capacity > 0x7FFFFFFFu) return 0; |
|
438
|
0 |
3 |
if (hdr->total_size != file_size) return 0; |
|
439
|
0 |
3 |
if (hdr->data_off != sizeof(DeqHeader)) return 0; |
|
440
|
0 |
3 |
if (hdr->ctl_off != deq_ctl_offset(hdr->elem_size, hdr->capacity)) return 0; |
|
441
|
0 |
3 |
if (hdr->total_size != deq_total_size(hdr->elem_size, hdr->capacity)) return 0; |
|
448
|
17 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
449
|
0 |
17 |
if (capacity == 0) { DEQ_ERR("capacity must be > 0"); return NULL; } |
|
|
0 |
0 |
if (capacity == 0) { DEQ_ERR("capacity must be > 0"); return NULL; } |
|
450
|
0 |
17 |
if (elem_size == 0) { DEQ_ERR("elem_size must be > 0"); return NULL; } |
|
|
0 |
0 |
if (elem_size == 0) { DEQ_ERR("elem_size must be > 0"); return NULL; } |
|
451
|
0 |
17 |
if (capacity > 0x7FFFFFFFu) { |
|
452
|
0 |
0 |
DEQ_ERR("capacity must be <= 2^31 (32-bit cursor halves)"); return NULL; |
|
461
|
11 |
6 |
if (anonymous) { |
|
464
|
0 |
11 |
if (base == MAP_FAILED) { DEQ_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { DEQ_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
467
|
0 |
6 |
if (fd < 0) { DEQ_ERR("open: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (fd < 0) { DEQ_ERR("open: %s", strerror(errno)); return NULL; } |
|
468
|
0 |
6 |
if (flock(fd, LOCK_EX) < 0) { DEQ_ERR("flock: %s", strerror(errno)); close(fd); return NULL; } |
|
|
0 |
0 |
if (flock(fd, LOCK_EX) < 0) { DEQ_ERR("flock: %s", strerror(errno)); close(fd); return NULL; } |
|
470
|
0 |
6 |
if (fstat(fd, &st) < 0) { |
|
471
|
0 |
0 |
DEQ_ERR("fstat: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; |
|
474
|
3 |
3 |
if (!is_new && (uint64_t)st.st_size < sizeof(DeqHeader)) { |
|
|
0 |
3 |
if (!is_new && (uint64_t)st.st_size < sizeof(DeqHeader)) { |
|
475
|
0 |
0 |
DEQ_ERR("%s: file too small (%lld)", path, (long long)st.st_size); |
|
478
|
3 |
3 |
if (is_new && ftruncate(fd, (off_t)total) < 0) { |
|
|
0 |
3 |
if (is_new && ftruncate(fd, (off_t)total) < 0) { |
|
479
|
0 |
0 |
DEQ_ERR("ftruncate: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; |
|
481
|
3 |
3 |
map_size = is_new ? (size_t)total : (size_t)st.st_size; |
|
483
|
0 |
6 |
if (base == MAP_FAILED) { DEQ_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { DEQ_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; } |
|
484
|
3 |
3 |
if (!is_new) { |
|
485
|
1 |
2 |
if (!deq_validate_header((DeqHeader *)base, (uint64_t)st.st_size, variant_id)) { |
|
486
|
1 |
0 |
DEQ_ERR("invalid deque file"); munmap(base, map_size); flock(fd, LOCK_UN); close(fd); return NULL; |
|
493
|
3 |
11 |
if (fd >= 0) { flock(fd, LOCK_UN); close(fd); } |
|
500
|
1 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
501
|
0 |
1 |
if (capacity == 0) { DEQ_ERR("capacity must be > 0"); return NULL; } |
|
|
0 |
0 |
if (capacity == 0) { DEQ_ERR("capacity must be > 0"); return NULL; } |
|
502
|
0 |
1 |
if (elem_size == 0) { DEQ_ERR("elem_size must be > 0"); return NULL; } |
|
|
0 |
0 |
if (elem_size == 0) { DEQ_ERR("elem_size must be > 0"); return NULL; } |
|
503
|
0 |
1 |
if (capacity > 0x7FFFFFFFu) { |
|
504
|
0 |
0 |
DEQ_ERR("capacity must be <= 2^31 (32-bit cursor halves)"); return NULL; |
|
507
|
1 |
0 |
int fd = memfd_create(name ? name : "deque", MFD_CLOEXEC | MFD_ALLOW_SEALING); |
|
508
|
0 |
1 |
if (fd < 0) { DEQ_ERR("memfd_create: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (fd < 0) { DEQ_ERR("memfd_create: %s", strerror(errno)); return NULL; } |
|
509
|
0 |
1 |
if (ftruncate(fd, (off_t)total) < 0) { DEQ_ERR("ftruncate: %s", strerror(errno)); close(fd); return NULL; } |
|
|
0 |
0 |
if (ftruncate(fd, (off_t)total) < 0) { DEQ_ERR("ftruncate: %s", strerror(errno)); close(fd); return NULL; } |
|
512
|
0 |
1 |
if (base == MAP_FAILED) { DEQ_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { DEQ_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; } |
|
518
|
1 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
520
|
0 |
1 |
if (fstat(fd, &st) < 0) { DEQ_ERR("fstat: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (fstat(fd, &st) < 0) { DEQ_ERR("fstat: %s", strerror(errno)); return NULL; } |
|
521
|
0 |
1 |
if ((uint64_t)st.st_size < sizeof(DeqHeader)) { DEQ_ERR("too small"); return NULL; } |
|
|
0 |
0 |
if ((uint64_t)st.st_size < sizeof(DeqHeader)) { DEQ_ERR("too small"); return NULL; } |
|
524
|
0 |
1 |
if (base == MAP_FAILED) { DEQ_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { DEQ_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
525
|
0 |
1 |
if (!deq_validate_header((DeqHeader *)base, (uint64_t)st.st_size, variant_id)) { |
|
526
|
0 |
0 |
DEQ_ERR("invalid deque"); munmap(base, ms); return NULL; |
|
529
|
0 |
1 |
if (myfd < 0) { DEQ_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; } |
|
|
0 |
0 |
if (myfd < 0) { DEQ_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; } |
|
534
|
0 |
18 |
if (!h) return; |
|
535
|
2 |
16 |
if (h->notify_fd >= 0) close(h->notify_fd); |
|
536
|
2 |
16 |
if (h->backing_fd >= 0) close(h->backing_fd); |
|
537
|
18 |
0 |
if (h->hdr) munmap(h->hdr, h->mmap_size); |
|
550
|
0 |
3 |
if (__atomic_load_n(&h->hdr->waiters_push, __ATOMIC_RELAXED) > 0) { |
|
554
|
0 |
3 |
if (__atomic_load_n(&h->hdr->waiters_pop, __ATOMIC_RELAXED) > 0) { |
|
569
|
1 |
1 |
if (count == 0) return 0; |
|
571
|
1 |
0 |
if (__atomic_compare_exchange_n(&hdr->cursor, &c, nc, |
|
573
|
5 |
1 |
for (uint32_t i = 0; i < count; i++) { |
|
579
|
0 |
1 |
if (__atomic_load_n(&hdr->waiters_push, __ATOMIC_RELAXED) > 0) { |
|
590
|
0 |
2 |
if (h->notify_fd >= 0) return h->notify_fd; |
|
592
|
0 |
2 |
if (efd < 0) return -1; |
|
596
|
0 |
2 |
if (h->notify_fd < 0) return 0; |
|
600
|
0 |
2 |
if (h->notify_fd < 0) return -1; |
|
602
|
0 |
2 |
if (read(h->notify_fd, &v, sizeof(v)) != sizeof(v)) return -1; |