| line |
true |
false |
branch |
|
143
|
0 |
0 |
if (pid == 0) return 1; /* no owner recorded, assume alive */ |
|
144
|
0 |
0 |
return !(kill((pid_t)pid, 0) == -1 && errno == ESRCH); |
|
|
0 |
0 |
return !(kill((pid_t)pid, 0) == -1 && errno == ESRCH); |
|
154
|
0 |
0 |
if (!__atomic_compare_exchange_n(&hdr->rwlock, &observed_rwlock, |
|
160
|
0 |
0 |
if (__atomic_load_n(&hdr->rwlock_waiters, __ATOMIC_RELAXED) > 0) |
|
184
|
17153 |
19 |
if (__builtin_expect(cur_gen == h->cached_fork_gen && h->my_slot_idx != UINT32_MAX, 1)) |
|
|
17153 |
0 |
if (__builtin_expect(cur_gen == h->cached_fork_gen && h->my_slot_idx != UINT32_MAX, 1)) |
|
195
|
21 |
0 |
for (uint32_t i = 0; i < CMS_READER_SLOTS; i++) { |
|
198
|
19 |
2 |
if (__atomic_compare_exchange_n(&h->reader_slots[s].pid, |
|
218
|
0 |
0 |
if (!sub) return; |
|
221
|
0 |
0 |
uint32_t want = (cur > sub) ? cur - sub : 0; |
|
222
|
0 |
0 |
if (__atomic_compare_exchange_n(p, &cur, want, |
|
245
|
0 |
0 |
if (!__atomic_compare_exchange_n(&h->reader_slots[i].pid, &expected, 0, |
|
250
|
0 |
0 |
if (wp) cms_atomic_sub_cap(&hdr->rwlock_waiters, wp); |
|
251
|
0 |
0 |
if (writp) cms_atomic_sub_cap(&hdr->rwlock_writers_waiting, writp); |
|
265
|
0 |
0 |
if (!h->reader_slots) return; |
|
278
|
0 |
0 |
for (uint32_t i = 0; i < CMS_READER_SLOTS; i++) { |
|
280
|
0 |
0 |
if (pid == 0) continue; |
|
282
|
0 |
0 |
if (cms_pid_alive(pid)) { |
|
283
|
0 |
0 |
if (sc > 0) any_live_reader = 1; |
|
286
|
0 |
0 |
if (sc > 0) { found_dead_reader = 1; continue; } |
|
303
|
0 |
0 |
if (found_dead_reader && !any_live_reader) { |
|
|
0 |
0 |
if (found_dead_reader && !any_live_reader) { |
|
305
|
0 |
0 |
if (cur > 0 && cur < CMS_RWLOCK_WRITER_BIT) { |
|
|
0 |
0 |
if (cur > 0 && cur < CMS_RWLOCK_WRITER_BIT) { |
|
306
|
0 |
0 |
if (__atomic_compare_exchange_n(&hdr->rwlock, &cur, 0, |
|
308
|
0 |
0 |
if (__atomic_load_n(&hdr->rwlock_waiters, __ATOMIC_RELAXED) > 0) |
|
312
|
0 |
0 |
for (uint32_t i = 0; i < CMS_READER_SLOTS; i++) { |
|
314
|
0 |
0 |
if (pid == 0 || cms_pid_alive(pid)) continue; |
|
|
0 |
0 |
if (pid == 0 || cms_pid_alive(pid)) continue; |
|
327
|
0 |
0 |
if (val >= CMS_RWLOCK_WRITER_BIT) { |
|
329
|
0 |
0 |
if (!cms_pid_alive(pid)) |
|
341
|
0 |
0 |
if (h->my_slot_idx != UINT32_MAX) |
|
347
|
0 |
0 |
if (h->my_slot_idx != UINT32_MAX) |
|
351
|
0 |
0 |
if (h->my_slot_idx != UINT32_MAX) { |
|
361
|
0 |
0 |
if (h->my_slot_idx != UINT32_MAX) { |
|
379
|
10038 |
0 |
if (h->my_slot_idx != UINT32_MAX) |
|
386
|
0 |
10038 |
if (cur > 0 && cur < CMS_RWLOCK_WRITER_BIT) { |
|
|
0 |
0 |
if (cur > 0 && cur < CMS_RWLOCK_WRITER_BIT) { |
|
387
|
0 |
0 |
if (__atomic_compare_exchange_n(lock, &cur, cur + 1, |
|
390
|
10038 |
0 |
} else if (cur == 0 && !__atomic_load_n(writers_waiting, __ATOMIC_RELAXED)) { |
|
|
10038 |
0 |
} else if (cur == 0 && !__atomic_load_n(writers_waiting, __ATOMIC_RELAXED)) { |
|
391
|
10038 |
0 |
if (__atomic_compare_exchange_n(lock, &cur, 1, |
|
395
|
0 |
0 |
if (__builtin_expect(spin < CMS_RWLOCK_SPIN_LIMIT, 1)) { |
|
402
|
0 |
0 |
if (cur >= CMS_RWLOCK_WRITER_BIT || cur == 0) { |
|
|
0 |
0 |
if (cur >= CMS_RWLOCK_WRITER_BIT || cur == 0) { |
|
405
|
0 |
0 |
if (rc == -1 && errno == ETIMEDOUT) { |
|
|
0 |
0 |
if (rc == -1 && errno == ETIMEDOUT) { |
|
425
|
10038 |
0 |
if (h->my_slot_idx != UINT32_MAX) |
|
427
|
10038 |
0 |
if (after == 0 && __atomic_load_n(&hdr->rwlock_waiters, __ATOMIC_RELAXED) > 0) |
|
|
0 |
10038 |
if (after == 0 && __atomic_load_n(&hdr->rwlock_waiters, __ATOMIC_RELAXED) > 0) |
|
440
|
7134 |
0 |
if (__atomic_compare_exchange_n(lock, &expected, mypid, |
|
443
|
0 |
0 |
if (__builtin_expect(spin < CMS_RWLOCK_SPIN_LIMIT, 1)) { |
|
449
|
0 |
0 |
if (cur != 0) { |
|
452
|
0 |
0 |
if (rc == -1 && errno == ETIMEDOUT) { |
|
|
0 |
0 |
if (rc == -1 && errno == ETIMEDOUT) { |
|
467
|
0 |
7134 |
if (__atomic_load_n(&hdr->rwlock_waiters, __ATOMIC_RELAXED) > 0) |
|
495
|
0 |
27 |
if (v <= CMS_MIN_W) return CMS_MIN_W; |
|
526
|
0 |
27 |
if (!h) { |
|
528
|
0 |
0 |
if (backing_fd >= 0) close(backing_fd); |
|
535
|
4 |
23 |
h->path = path ? strdup(path) : NULL; |
|
543
|
0 |
2 |
if (hdr->magic != CMS_MAGIC) return 0; |
|
544
|
0 |
2 |
if (hdr->version != CMS_VERSION) return 0; |
|
545
|
2 |
0 |
if (hdr->d < CMS_MIN_D || hdr->d > CMS_MAX_D) return 0; |
|
|
0 |
2 |
if (hdr->d < CMS_MIN_D || hdr->d > CMS_MAX_D) return 0; |
|
546
|
2 |
0 |
if (hdr->w < CMS_MIN_W || hdr->w > CMS_MAX_W) return 0; |
|
|
0 |
2 |
if (hdr->w < CMS_MIN_W || hdr->w > CMS_MAX_W) return 0; |
|
547
|
0 |
2 |
if ((hdr->w & (hdr->w - 1)) != 0) return 0; /* power of two */ |
|
548
|
0 |
2 |
if (hdr->mask != hdr->w - 1) return 0; |
|
549
|
0 |
2 |
if (hdr->total_size != file_size) return 0; |
|
550
|
0 |
2 |
if (hdr->total_size != cms_total_size(hdr->w, hdr->d)) return 0; |
|
552
|
0 |
2 |
if (hdr->reader_slots_off != L.reader_slots) return 0; |
|
553
|
0 |
2 |
if (hdr->counters_off != L.counters) return 0; |
|
562
|
35 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
563
|
33 |
2 |
if (!(epsilon > 0.0 && epsilon < 1.0)) { CMS_ERR("epsilon must be between 0 and 1 (exclusive)"); return 0; } |
|
|
2 |
31 |
if (!(epsilon > 0.0 && epsilon < 1.0)) { CMS_ERR("epsilon must be between 0 and 1 (exclusive)"); return 0; } |
|
|
4 |
0 |
if (!(epsilon > 0.0 && epsilon < 1.0)) { CMS_ERR("epsilon must be between 0 and 1 (exclusive)"); return 0; } |
|
564
|
30 |
1 |
if (!(delta > 0.0 && delta < 1.0)) { CMS_ERR("delta must be between 0 and 1 (exclusive)"); return 0; } |
|
|
2 |
28 |
if (!(delta > 0.0 && delta < 1.0)) { CMS_ERR("delta must be between 0 and 1 (exclusive)"); return 0; } |
|
|
3 |
0 |
if (!(delta > 0.0 && delta < 1.0)) { CMS_ERR("delta must be between 0 and 1 (exclusive)"); return 0; } |
|
570
|
1 |
27 |
if (w_opt_d > (double)CMS_MAX_W) { CMS_ERR("epsilon too small for the column cap"); return 0; } |
|
|
1 |
0 |
if (w_opt_d > (double)CMS_MAX_W) { CMS_ERR("epsilon too small for the column cap"); return 0; } |
|
576
|
0 |
27 |
if (dl < CMS_MIN_D) dl = CMS_MIN_D; |
|
577
|
0 |
27 |
if (dl > CMS_MAX_D) dl = CMS_MAX_D; |
|
588
|
6 |
25 |
if (!cms_validate_create_args(epsilon, delta, &w, &d, errbuf)) return NULL; |
|
596
|
20 |
5 |
if (anonymous) { |
|
599
|
0 |
20 |
if (base == MAP_FAILED) { CMS_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { CMS_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
602
|
0 |
5 |
if (fd < 0) { CMS_ERR("open: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (fd < 0) { CMS_ERR("open: %s", strerror(errno)); return NULL; } |
|
603
|
0 |
5 |
if (flock(fd, LOCK_EX) < 0) { CMS_ERR("flock: %s", strerror(errno)); close(fd); return NULL; } |
|
|
0 |
0 |
if (flock(fd, LOCK_EX) < 0) { CMS_ERR("flock: %s", strerror(errno)); close(fd); return NULL; } |
|
605
|
0 |
5 |
if (fstat(fd, &st) < 0) { CMS_ERR("fstat: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; } |
|
|
0 |
0 |
if (fstat(fd, &st) < 0) { CMS_ERR("fstat: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; } |
|
607
|
2 |
3 |
if (!is_new && (uint64_t)st.st_size < sizeof(CmsHeader)) { |
|
|
1 |
1 |
if (!is_new && (uint64_t)st.st_size < sizeof(CmsHeader)) { |
|
608
|
1 |
0 |
CMS_ERR("%s: file too small (%lld)", path, (long long)st.st_size); |
|
611
|
3 |
1 |
if (is_new && ftruncate(fd, (off_t)total) < 0) { |
|
|
0 |
3 |
if (is_new && ftruncate(fd, (off_t)total) < 0) { |
|
612
|
0 |
0 |
CMS_ERR("ftruncate: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; |
|
614
|
1 |
3 |
map_size = is_new ? (size_t)total : (size_t)st.st_size; |
|
616
|
0 |
4 |
if (base == MAP_FAILED) { CMS_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { CMS_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; } |
|
617
|
1 |
3 |
if (!is_new) { |
|
618
|
0 |
1 |
if (!cms_validate_header((CmsHeader *)base, (uint64_t)st.st_size)) { |
|
619
|
0 |
0 |
CMS_ERR("invalid Count-Min sketch file"); munmap(base, map_size); flock(fd, LOCK_UN); close(fd); return NULL; |
|
626
|
3 |
20 |
if (fd >= 0) { flock(fd, LOCK_UN); close(fd); } |
|
633
|
2 |
2 |
if (!cms_validate_create_args(epsilon, delta, &w, &d, errbuf)) return NULL; |
|
636
|
1 |
1 |
int fd = memfd_create(name ? name : "cms", MFD_CLOEXEC | MFD_ALLOW_SEALING); |
|
637
|
0 |
2 |
if (fd < 0) { CMS_ERR("memfd_create: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (fd < 0) { CMS_ERR("memfd_create: %s", strerror(errno)); return NULL; } |
|
638
|
0 |
2 |
if (ftruncate(fd, (off_t)total) < 0) { |
|
639
|
0 |
0 |
CMS_ERR("ftruncate: %s", strerror(errno)); close(fd); return NULL; |
|
643
|
0 |
2 |
if (base == MAP_FAILED) { CMS_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { CMS_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; } |
|
649
|
2 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
651
|
0 |
2 |
if (fstat(fd, &st) < 0) { CMS_ERR("fstat: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (fstat(fd, &st) < 0) { CMS_ERR("fstat: %s", strerror(errno)); return NULL; } |
|
652
|
1 |
1 |
if ((uint64_t)st.st_size < sizeof(CmsHeader)) { CMS_ERR("too small"); return NULL; } |
|
|
1 |
0 |
if ((uint64_t)st.st_size < sizeof(CmsHeader)) { CMS_ERR("too small"); return NULL; } |
|
655
|
0 |
1 |
if (base == MAP_FAILED) { CMS_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { CMS_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
656
|
0 |
1 |
if (!cms_validate_header((CmsHeader *)base, (uint64_t)st.st_size)) { |
|
657
|
0 |
0 |
CMS_ERR("invalid Count-Min sketch table"); munmap(base, ms); return NULL; |
|
660
|
0 |
1 |
if (myfd < 0) { CMS_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; } |
|
|
0 |
0 |
if (myfd < 0) { CMS_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; } |
|
665
|
0 |
27 |
if (!h) return; |
|
666
|
3 |
24 |
if (h->backing_fd >= 0) close(h->backing_fd); |
|
667
|
27 |
0 |
if (h->base) munmap(h->base, h->mmap_size); |
|
673
|
2 |
0 |
if (!h || !h->base) return 0; |
|
|
0 |
2 |
if (!h || !h->base) return 0; |
|
698
|
67382 |
9626 |
for (uint32_t r = 0; r < d; r++) { |
|
715
|
70126 |
10018 |
for (uint32_t r = 0; r < d; r++) { |
|
718
|
14276 |
55850 |
if (v < m) m = v; |
|
726
|
86016 |
3 |
for (uint64_t i = 0; i < cells; i++) { |
|
727
|
0 |
86016 |
if (dst[i] > UINT64_MAX - src[i]) dst[i] = UINT64_MAX; |