| line |
true |
false |
branch |
|
87
|
0 |
0 |
if (pid == 0) return 1; |
|
88
|
0 |
0 |
return !(kill((pid_t)pid, 0) == -1 && errno == ESRCH); |
|
|
0 |
0 |
return !(kill((pid_t)pid, 0) == -1 && errno == ESRCH); |
|
95
|
99 |
0 |
if (__atomic_compare_exchange_n(&hdr->mutex, &expected, mypid, |
|
98
|
0 |
0 |
if (spin < HEAP_SPIN_LIMIT) { |
|
108
|
0 |
0 |
if (cur != 0) { |
|
111
|
0 |
0 |
if (rc == -1 && errno == ETIMEDOUT && cur >= HEAP_MUTEX_BIT) { |
|
|
0 |
0 |
if (rc == -1 && errno == ETIMEDOUT && cur >= HEAP_MUTEX_BIT) { |
|
|
0 |
0 |
if (rc == -1 && errno == ETIMEDOUT && cur >= HEAP_MUTEX_BIT) { |
|
113
|
0 |
0 |
if (!heap_pid_alive(pid)) { |
|
114
|
0 |
0 |
if (__atomic_compare_exchange_n(&hdr->mutex, &cur, 0, |
|
118
|
0 |
0 |
if (__atomic_load_n(&hdr->mutex_waiters, __ATOMIC_RELAXED) > 0) |
|
131
|
0 |
99 |
if (__atomic_load_n(&hdr->mutex_waiters, __ATOMIC_RELAXED) > 0) |
|
144
|
43 |
24 |
while (idx > 0) { |
|
146
|
29 |
14 |
if (data[parent].priority <= data[idx].priority) break; |
|
157
|
23 |
19 |
if (left < size && data[left].priority < data[smallest].priority) |
|
|
19 |
4 |
if (left < size && data[left].priority < data[smallest].priority) |
|
159
|
14 |
28 |
if (right < size && data[right].priority < data[smallest].priority) |
|
|
5 |
9 |
if (right < size && data[right].priority < data[smallest].priority) |
|
161
|
23 |
19 |
if (smallest == idx) break; |
|
175
|
0 |
2 |
if (dl->tv_nsec >= 1000000000L) { dl->tv_sec++; dl->tv_nsec -= 1000000000L; } |
|
183
|
2 |
1 |
if (rem->tv_nsec < 0) { rem->tv_sec--; rem->tv_nsec += 1000000000L; } |
|
190
|
4 |
53 |
if (hdr->size >= (uint32_t)hdr->capacity) { |
|
201
|
0 |
53 |
if (__atomic_load_n(&hdr->waiters_pop, __ATOMIC_RELAXED) > 0) |
|
209
|
5 |
32 |
if (hdr->size == 0) { |
|
216
|
23 |
9 |
if (hdr->size > 0) { |
|
226
|
0 |
2 |
if (heap_pop(h, out_p, out_v)) return 1; |
|
227
|
0 |
2 |
if (timeout == 0) return 0; |
|
232
|
2 |
0 |
if (has_dl) heap_make_deadline(timeout, &dl); |
|
238
|
2 |
0 |
if (cur == 0) { |
|
240
|
2 |
0 |
if (has_dl) { |
|
241
|
0 |
2 |
if (!heap_remaining(&dl, &rem)) { |
|
251
|
1 |
1 |
if (heap_pop(h, out_p, out_v)) return 1; |
|
252
|
1 |
0 |
if (has_dl && !heap_remaining(&dl, &rem)) { |
|
|
1 |
0 |
if (has_dl && !heap_remaining(&dl, &rem)) { |
|
262
|
0 |
2 |
if (hdr->size == 0) { heap_mutex_unlock(hdr); return 0; } |
|
292
|
0 |
2 |
if (hdr->magic != HEAP_MAGIC) return 0; |
|
293
|
0 |
2 |
if (hdr->version != HEAP_VERSION) return 0; |
|
294
|
0 |
2 |
if (hdr->capacity == 0) return 0; |
|
295
|
0 |
2 |
if (hdr->capacity > (UINT64_MAX - sizeof(HeapHeader)) / sizeof(HeapEntry)) return 0; |
|
296
|
0 |
2 |
if (hdr->total_size != file_size) return 0; |
|
297
|
0 |
2 |
if (hdr->data_off != sizeof(HeapHeader)) return 0; |
|
299
|
0 |
2 |
if (hdr->total_size != exp_total) return 0; |
|
301
|
0 |
2 |
if (hdr->size > hdr->capacity) return 0; |
|
308
|
0 |
17 |
if (!h) { munmap(base, ms); return NULL; } |
|
312
|
3 |
14 |
h->path = path ? strdup(path) : NULL; |
|
319
|
9 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
320
|
0 |
9 |
if (capacity == 0) { HEAP_ERR("capacity must be > 0"); return NULL; } |
|
|
0 |
0 |
if (capacity == 0) { HEAP_ERR("capacity must be > 0"); return NULL; } |
|
321
|
0 |
9 |
if (capacity > (UINT64_MAX - sizeof(HeapHeader)) / sizeof(HeapEntry)) { |
|
322
|
0 |
0 |
HEAP_ERR("capacity overflow"); return NULL; |
|
331
|
6 |
3 |
if (anonymous) { |
|
334
|
0 |
6 |
if (base == MAP_FAILED) { HEAP_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { HEAP_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
337
|
0 |
3 |
if (fd < 0) { HEAP_ERR("open: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (fd < 0) { HEAP_ERR("open: %s", strerror(errno)); return NULL; } |
|
338
|
0 |
3 |
if (flock(fd, LOCK_EX) < 0) { HEAP_ERR("flock: %s", strerror(errno)); close(fd); return NULL; } |
|
|
0 |
0 |
if (flock(fd, LOCK_EX) < 0) { HEAP_ERR("flock: %s", strerror(errno)); close(fd); return NULL; } |
|
340
|
0 |
3 |
if (fstat(fd, &st) < 0) { HEAP_ERR("fstat: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; } |
|
|
0 |
0 |
if (fstat(fd, &st) < 0) { HEAP_ERR("fstat: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; } |
|
342
|
1 |
2 |
if (!is_new && (uint64_t)st.st_size < sizeof(HeapHeader)) { |
|
|
0 |
1 |
if (!is_new && (uint64_t)st.st_size < sizeof(HeapHeader)) { |
|
343
|
0 |
0 |
HEAP_ERR("%s: file too small (%lld)", path, (long long)st.st_size); |
|
346
|
2 |
1 |
if (is_new && ftruncate(fd, (off_t)total) < 0) { |
|
|
0 |
2 |
if (is_new && ftruncate(fd, (off_t)total) < 0) { |
|
347
|
0 |
0 |
HEAP_ERR("ftruncate: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; |
|
349
|
1 |
2 |
map_size = is_new ? (size_t)total : (size_t)st.st_size; |
|
351
|
0 |
3 |
if (base == MAP_FAILED) { HEAP_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { HEAP_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; } |
|
352
|
1 |
2 |
if (!is_new) { |
|
353
|
0 |
1 |
if (!heap_validate_header((HeapHeader *)base, (uint64_t)st.st_size)) { |
|
354
|
0 |
0 |
HEAP_ERR("invalid heap file"); munmap(base, map_size); flock(fd, LOCK_UN); close(fd); return NULL; |
|
361
|
2 |
6 |
if (fd >= 0) { flock(fd, LOCK_UN); close(fd); } |
|
366
|
7 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
367
|
0 |
7 |
if (capacity == 0) { HEAP_ERR("capacity must be > 0"); return NULL; } |
|
|
0 |
0 |
if (capacity == 0) { HEAP_ERR("capacity must be > 0"); return NULL; } |
|
368
|
0 |
7 |
if (capacity > (UINT64_MAX - sizeof(HeapHeader)) / sizeof(HeapEntry)) { |
|
369
|
0 |
0 |
HEAP_ERR("capacity overflow"); return NULL; |
|
372
|
7 |
0 |
int fd = memfd_create(name ? name : "heap", MFD_CLOEXEC | MFD_ALLOW_SEALING); |
|
373
|
0 |
7 |
if (fd < 0) { HEAP_ERR("memfd_create: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (fd < 0) { HEAP_ERR("memfd_create: %s", strerror(errno)); return NULL; } |
|
374
|
0 |
7 |
if (ftruncate(fd, (off_t)total) < 0) { HEAP_ERR("ftruncate: %s", strerror(errno)); close(fd); return NULL; } |
|
|
0 |
0 |
if (ftruncate(fd, (off_t)total) < 0) { HEAP_ERR("ftruncate: %s", strerror(errno)); close(fd); return NULL; } |
|
377
|
0 |
7 |
if (base == MAP_FAILED) { HEAP_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { HEAP_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; } |
|
383
|
1 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
385
|
0 |
1 |
if (fstat(fd, &st) < 0) { HEAP_ERR("fstat: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (fstat(fd, &st) < 0) { HEAP_ERR("fstat: %s", strerror(errno)); return NULL; } |
|
386
|
0 |
1 |
if ((uint64_t)st.st_size < sizeof(HeapHeader)) { HEAP_ERR("too small"); return NULL; } |
|
|
0 |
0 |
if ((uint64_t)st.st_size < sizeof(HeapHeader)) { HEAP_ERR("too small"); return NULL; } |
|
389
|
0 |
1 |
if (base == MAP_FAILED) { HEAP_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
|
0 |
0 |
if (base == MAP_FAILED) { HEAP_ERR("mmap: %s", strerror(errno)); return NULL; } |
|
390
|
0 |
1 |
if (!heap_validate_header((HeapHeader *)base, (uint64_t)st.st_size)) { |
|
391
|
0 |
0 |
HEAP_ERR("invalid heap"); munmap(base, ms); return NULL; |
|
394
|
0 |
1 |
if (myfd < 0) { HEAP_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; } |
|
|
0 |
0 |
if (myfd < 0) { HEAP_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; } |
|
399
|
0 |
17 |
if (!h) return; |
|
400
|
2 |
15 |
if (h->notify_fd >= 0) close(h->notify_fd); |
|
401
|
8 |
9 |
if (h->backing_fd >= 0) close(h->backing_fd); |
|
402
|
17 |
0 |
if (h->hdr) munmap(h->hdr, h->mmap_size); |
|
412
|
0 |
3 |
if (__atomic_load_n(&h->hdr->waiters_pop, __ATOMIC_RELAXED) > 0) |
|
417
|
0 |
2 |
if (h->notify_fd >= 0) return h->notify_fd; |
|
419
|
0 |
2 |
if (efd < 0) return -1; |
|
423
|
0 |
2 |
if (h->notify_fd < 0) return 0; |
|
427
|
0 |
2 |
if (h->notify_fd < 0) return -1; |
|
429
|
0 |
2 |
if (read(h->notify_fd, &v, sizeof(v)) != sizeof(v)) return -1; |