| line |
true |
false |
branch |
|
116
|
1 |
6 |
if (dl->tv_nsec >= 1000000000L) { dl->tv_sec++; dl->tv_nsec -= 1000000000L; } |
|
124
|
3835 |
16506 |
if (rem->tv_nsec < 0) { rem->tv_sec--; rem->tv_nsec += 1000000000L; } |
|
155
|
98 |
0 |
if (DEQ_SLOT_STATE(c) == DEQ_SLOT_EMPTY) { |
|
157
|
98 |
0 |
if (__atomic_compare_exchange_n(ctl_word, &c, nc, |
|
185
|
18055 |
0 |
if (DEQ_SLOT_STATE(c) == DEQ_SLOT_FILLED) { |
|
187
|
18055 |
0 |
if (__atomic_compare_exchange_n(ctl_word, &c, nc, |
|
210
|
5 |
88 |
if ((uint32_t)(t - hd) >= cap) return 0; |
|
212
|
88 |
0 |
if (__atomic_compare_exchange_n(&hdr->cursor, &c, nc, |
|
219
|
0 |
88 |
if (cp < sz) memset(deq_slot(h, t) + cp, 0, sz - cp); |
|
222
|
0 |
88 |
if (__atomic_load_n(&hdr->waiters_pop, __ATOMIC_RELAXED) > 0) { |
|
241
|
5 |
10 |
if ((uint32_t)(t - hd) >= cap) return 0; |
|
244
|
10 |
0 |
if (__atomic_compare_exchange_n(&hdr->cursor, &c, nc, |
|
251
|
0 |
10 |
if (cp < sz) memset(deq_slot(h, new_hd) + cp, 0, sz - cp); |
|
254
|
0 |
10 |
if (__atomic_load_n(&hdr->waiters_pop, __ATOMIC_RELAXED) > 0) { |
|
273
|
6 |
18045 |
if ((uint32_t)(t - hd) == 0) return 0; |
|
275
|
18045 |
0 |
if (__atomic_compare_exchange_n(&hdr->cursor, &c, nc, |
|
282
|
0 |
18045 |
if (__atomic_load_n(&hdr->waiters_push, __ATOMIC_RELAXED) > 0) { |
|
301
|
4 |
10 |
if ((uint32_t)(t - hd) == 0) return 0; |
|
303
|
10 |
0 |
if (__atomic_compare_exchange_n(&hdr->cursor, &c, nc, |
|
310
|
0 |
10 |
if (__atomic_load_n(&hdr->waiters_push, __ATOMIC_RELAXED) > 0) { |
|
326
|
1 |
1 |
front ? deq_try_push_front : deq_try_push_back; |
|
327
|
0 |
2 |
if (try_fn(h, val, vlen)) return 1; |
|
328
|
0 |
2 |
if (timeout == 0) return 0; |
|
333
|
2 |
0 |
if (has_dl) deq_make_deadline(timeout, &dl); |
|
341
|
2 |
0 |
if (DEQ_CURSOR_SIZE(c) >= cap) { |
|
343
|
2 |
0 |
if (has_dl) { |
|
344
|
0 |
2 |
if (!deq_remaining(&dl, &rem)) { |
|
354
|
0 |
2 |
if (try_fn(h, val, vlen)) return 1; |
|
355
|
2 |
0 |
if (has_dl && !deq_remaining(&dl, &rem)) { |
|
|
2 |
0 |
if (has_dl && !deq_remaining(&dl, &rem)) { |
|
364
|
1 |
2 |
back ? deq_try_pop_back : deq_try_pop_front; |
|
365
|
0 |
3 |
if (try_fn(h, out)) return 1; |
|
366
|
0 |
3 |
if (timeout == 0) return 0; |
|
371
|
3 |
0 |
if (has_dl) deq_make_deadline(timeout, &dl); |
|
378
|
3 |
0 |
if (DEQ_CURSOR_SIZE(c) == 0) { |
|
380
|
3 |
0 |
if (has_dl) { |
|
381
|
0 |
3 |
if (!deq_remaining(&dl, &rem)) { |
|
391
|
1 |
2 |
if (try_fn(h, out)) return 1; |
|
392
|
2 |
0 |
if (has_dl && !deq_remaining(&dl, &rem)) { |
|
|
2 |
0 |
if (has_dl && !deq_remaining(&dl, &rem)) { |
|
434
|
0 |
20 |
if (!h) { munmap(base, ms); return NULL; } |
|
440
|
7 |
13 |
h->path = path ? strdup(path) : NULL; |
|
449
|
1 |
5 |
if (hdr->magic != DEQ_MAGIC) return 0; |
|
450
|
0 |
5 |
if (hdr->version != DEQ_VERSION) return 0; |
|
451
|
0 |
5 |
if (hdr->variant_id != expected_variant) return 0; |
|
452
|
5 |
0 |
if (hdr->elem_size == 0 || hdr->capacity == 0) return 0; |
|
|
0 |
5 |
if (hdr->elem_size == 0 || hdr->capacity == 0) return 0; |
|
453
|
0 |
5 |
if (hdr->capacity > 0x7FFFFFFFu) return 0; |
|
458
|
3 |
2 |
if (expected_variant == DEQ_VAR_INT && hdr->elem_size != sizeof(int64_t)) |
|
|
1 |
2 |
if (expected_variant == DEQ_VAR_INT && hdr->elem_size != sizeof(int64_t)) |
|
460
|
2 |
2 |
if (expected_variant == DEQ_VAR_STR && hdr->elem_size < sizeof(uint32_t) + 1) |
|
|
1 |
1 |
if (expected_variant == DEQ_VAR_STR && hdr->elem_size < sizeof(uint32_t) + 1) |
|
462
|
0 |
3 |
if (hdr->total_size != file_size) return 0; |
|
463
|
0 |
3 |
if (hdr->data_off != sizeof(DeqHeader)) return 0; |
|
464
|
0 |
3 |
if (hdr->ctl_off != deq_ctl_offset(hdr->elem_size, hdr->capacity)) return 0; |
|
465
|
0 |
3 |
if (hdr->total_size != deq_total_size(hdr->elem_size, hdr->capacity)) return 0; |
|
472
|
21 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
473
|
0 |
21 |
if (capacity == 0) { DEQ_ERR("capacity must be > 0"); return NULL; } |
|
|
0 |
0 |
if (capacity == 0) { DEQ_ERR("capacity must be > 0"); return NULL; } |
|
474
|
0 |
21 |
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; } |
|
475
|
0 |
21 |
if (capacity > 0x7FFFFFFFu) { |
|
476
|
0 |
0 |
DEQ_ERR("capacity must be <= 2^31 (32-bit cursor halves)"); return NULL; |
|
485
|
11 |
10 |
if (anonymous) { |
|
488
|
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; } |
|
491
|
0 |
10 |
if (fd < 0) { DEQ_ERR("open: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (fd < 0) { DEQ_ERR("open: %s", strerror(errno)); return NULL; } |
|
492
|
0 |
10 |
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; } |
|
494
|
0 |
10 |
if (fstat(fd, &st) < 0) { |
|
495
|
0 |
0 |
DEQ_ERR("fstat: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; |
|
498
|
5 |
5 |
if (!is_new && (uint64_t)st.st_size < sizeof(DeqHeader)) { |
|
|
0 |
5 |
if (!is_new && (uint64_t)st.st_size < sizeof(DeqHeader)) { |
|
499
|
0 |
0 |
DEQ_ERR("%s: file too small (%lld)", path, (long long)st.st_size); |
|
502
|
5 |
5 |
if (is_new && ftruncate(fd, (off_t)total) < 0) { |
|
|
0 |
5 |
if (is_new && ftruncate(fd, (off_t)total) < 0) { |
|
503
|
0 |
0 |
DEQ_ERR("ftruncate: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; |
|
505
|
5 |
5 |
map_size = is_new ? (size_t)total : (size_t)st.st_size; |
|
507
|
0 |
10 |
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; } |
|
508
|
5 |
5 |
if (!is_new) { |
|
509
|
3 |
2 |
if (!deq_validate_header((DeqHeader *)base, (uint64_t)st.st_size, variant_id)) { |
|
510
|
3 |
0 |
DEQ_ERR("invalid deque file"); munmap(base, map_size); flock(fd, LOCK_UN); close(fd); return NULL; |
|
517
|
5 |
11 |
if (fd >= 0) { flock(fd, LOCK_UN); close(fd); } |
|
524
|
1 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
525
|
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; } |
|
526
|
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; } |
|
527
|
0 |
1 |
if (capacity > 0x7FFFFFFFu) { |
|
528
|
0 |
0 |
DEQ_ERR("capacity must be <= 2^31 (32-bit cursor halves)"); return NULL; |
|
531
|
1 |
0 |
int fd = memfd_create(name ? name : "deque", MFD_CLOEXEC | MFD_ALLOW_SEALING); |
|
532
|
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; } |
|
533
|
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; } |
|
536
|
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; } |
|
542
|
1 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
544
|
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; } |
|
545
|
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; } |
|
548
|
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; } |
|
549
|
0 |
1 |
if (!deq_validate_header((DeqHeader *)base, (uint64_t)st.st_size, variant_id)) { |
|
550
|
0 |
0 |
DEQ_ERR("invalid deque"); munmap(base, ms); return NULL; |
|
553
|
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; } |
|
558
|
0 |
20 |
if (!h) return; |
|
559
|
2 |
18 |
if (h->notify_fd >= 0) close(h->notify_fd); |
|
560
|
2 |
18 |
if (h->backing_fd >= 0) close(h->backing_fd); |
|
561
|
20 |
0 |
if (h->hdr) munmap(h->hdr, h->mmap_size); |
|
574
|
0 |
3 |
if (__atomic_load_n(&h->hdr->waiters_push, __ATOMIC_RELAXED) > 0) { |
|
578
|
0 |
3 |
if (__atomic_load_n(&h->hdr->waiters_pop, __ATOMIC_RELAXED) > 0) { |
|
608
|
1 |
3 |
if (count == 0) return 0; |
|
610
|
3 |
0 |
if (__atomic_compare_exchange_n(&hdr->cursor, &c, nc, |
|
612
|
13 |
3 |
for (uint32_t i = 0; i < count; i++) { |
|
622
|
11 |
1301248 |
if (st == DEQ_SLOT_FILLED) { |
|
624
|
11 |
0 |
if (__atomic_compare_exchange_n(ctl_word, &cw, nw, |
|
635
|
20332 |
1280916 |
if ((++spins & 0x3F) == 0) { |
|
636
|
2 |
20330 |
if (!dl_set) { |
|
641
|
2 |
20330 |
if (!deq_remaining(&dl, &rem)) { |
|
643
|
2 |
0 |
if (__atomic_compare_exchange_n(ctl_word, &cw, nw, |
|
657
|
2 |
11 |
if (recovered) |
|
661
|
0 |
3 |
if (__atomic_load_n(&hdr->waiters_push, __ATOMIC_RELAXED) > 0) { |
|
663
|
0 |
0 |
syscall(SYS_futex, &hdr->push_wake_seq, FUTEX_WAKE, |
|
673
|
0 |
2 |
if (h->notify_fd >= 0) return h->notify_fd; |
|
675
|
0 |
2 |
if (efd < 0) return -1; |
|
679
|
0 |
2 |
if (h->notify_fd < 0) return 0; |
|
683
|
0 |
2 |
if (h->notify_fd < 0) return -1; |
|
685
|
0 |
2 |
if (read(h->notify_fd, &v, sizeof(v)) != sizeof(v)) return -1; |