| line |
true |
false |
branch |
|
92
|
0 |
0 |
if (pid == 0) return 1; |
|
93
|
0 |
0 |
return !(kill((pid_t)pid, 0) == -1 && errno == ESRCH); |
|
|
0 |
0 |
return !(kill((pid_t)pid, 0) == -1 && errno == ESRCH); |
|
100
|
99 |
0 |
if (__atomic_compare_exchange_n(&hdr->mutex, &expected, mypid, |
|
103
|
0 |
0 |
if (spin < HEAP_SPIN_LIMIT) { |
|
113
|
0 |
0 |
if (cur != 0) { |
|
116
|
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) { |
|
118
|
0 |
0 |
if (!heap_pid_alive(pid)) { |
|
119
|
0 |
0 |
if (__atomic_compare_exchange_n(&hdr->mutex, &cur, 0, |
|
123
|
0 |
0 |
if (__atomic_load_n(&hdr->mutex_waiters, __ATOMIC_RELAXED) > 0) |
|
136
|
0 |
99 |
if (__atomic_load_n(&hdr->mutex_waiters, __ATOMIC_RELAXED) > 0) |
|
149
|
43 |
24 |
while (idx > 0) { |
|
151
|
29 |
14 |
if (data[parent].priority <= data[idx].priority) break; |
|
162
|
23 |
19 |
if (left < size && data[left].priority < data[smallest].priority) |
|
|
19 |
4 |
if (left < size && data[left].priority < data[smallest].priority) |
|
164
|
14 |
28 |
if (right < size && data[right].priority < data[smallest].priority) |
|
|
5 |
9 |
if (right < size && data[right].priority < data[smallest].priority) |
|
166
|
23 |
19 |
if (smallest == idx) break; |
|
180
|
0 |
2 |
if (dl->tv_nsec >= 1000000000L) { dl->tv_sec++; dl->tv_nsec -= 1000000000L; } |
|
188
|
2 |
1 |
if (rem->tv_nsec < 0) { rem->tv_sec--; rem->tv_nsec += 1000000000L; } |
|
195
|
4 |
53 |
if (hdr->size >= (uint32_t)hdr->capacity) { |
|
206
|
0 |
53 |
if (__atomic_load_n(&hdr->waiters_pop, __ATOMIC_RELAXED) > 0) |
|
214
|
5 |
32 |
if (hdr->size == 0) { |
|
221
|
23 |
9 |
if (hdr->size > 0) { |
|
231
|
0 |
2 |
if (heap_pop(h, out_p, out_v)) return 1; |
|
232
|
0 |
2 |
if (timeout == 0) return 0; |
|
237
|
2 |
0 |
if (has_dl) heap_make_deadline(timeout, &dl); |
|
243
|
2 |
0 |
if (cur == 0) { |
|
245
|
2 |
0 |
if (has_dl) { |
|
246
|
0 |
2 |
if (!heap_remaining(&dl, &rem)) { |
|
256
|
1 |
1 |
if (heap_pop(h, out_p, out_v)) return 1; |
|
257
|
1 |
0 |
if (has_dl && !heap_remaining(&dl, &rem)) { |
|
|
1 |
0 |
if (has_dl && !heap_remaining(&dl, &rem)) { |
|
267
|
0 |
2 |
if (hdr->size == 0) { heap_mutex_unlock(hdr); return 0; } |
|
297
|
0 |
2 |
if (hdr->magic != HEAP_MAGIC) return 0; |
|
298
|
0 |
2 |
if (hdr->version != HEAP_VERSION) return 0; |
|
299
|
2 |
0 |
if (hdr->capacity == 0 || hdr->capacity > HEAP_MAX_CAPACITY) return 0; |
|
|
0 |
2 |
if (hdr->capacity == 0 || hdr->capacity > HEAP_MAX_CAPACITY) return 0; |
|
300
|
0 |
2 |
if (hdr->total_size != file_size) return 0; |
|
301
|
0 |
2 |
if (hdr->data_off != sizeof(HeapHeader)) return 0; |
|
303
|
0 |
2 |
if (hdr->total_size != exp_total) return 0; |
|
305
|
0 |
2 |
if (hdr->size > hdr->capacity) return 0; |
|
312
|
0 |
17 |
if (!h) { |
|
314
|
0 |
0 |
if (bfd >= 0) close(bfd); |
|
320
|
3 |
14 |
h->path = path ? strdup(path) : NULL; |
|
327
|
9 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
328
|
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; } |
|
329
|
0 |
9 |
if (capacity > HEAP_MAX_CAPACITY) { HEAP_ERR("capacity too large (max %u)", (unsigned)HEAP_MAX_CAPACITY); return NULL; } |
|
|
0 |
0 |
if (capacity > HEAP_MAX_CAPACITY) { HEAP_ERR("capacity too large (max %u)", (unsigned)HEAP_MAX_CAPACITY); return NULL; } |
|
330
|
0 |
9 |
if (capacity > (UINT64_MAX - sizeof(HeapHeader)) / sizeof(HeapEntry)) { |
|
331
|
0 |
0 |
HEAP_ERR("capacity overflow"); return NULL; |
|
340
|
6 |
3 |
if (anonymous) { |
|
343
|
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; } |
|
346
|
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; } |
|
347
|
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; } |
|
349
|
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; } |
|
351
|
1 |
2 |
if (!is_new && (uint64_t)st.st_size < sizeof(HeapHeader)) { |
|
|
0 |
1 |
if (!is_new && (uint64_t)st.st_size < sizeof(HeapHeader)) { |
|
352
|
0 |
0 |
HEAP_ERR("%s: file too small (%lld)", path, (long long)st.st_size); |
|
355
|
2 |
1 |
if (is_new && ftruncate(fd, (off_t)total) < 0) { |
|
|
0 |
2 |
if (is_new && ftruncate(fd, (off_t)total) < 0) { |
|
356
|
0 |
0 |
HEAP_ERR("ftruncate: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; |
|
358
|
1 |
2 |
map_size = is_new ? (size_t)total : (size_t)st.st_size; |
|
360
|
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; } |
|
361
|
1 |
2 |
if (!is_new) { |
|
362
|
0 |
1 |
if (!heap_validate_header((HeapHeader *)base, (uint64_t)st.st_size)) { |
|
363
|
0 |
0 |
HEAP_ERR("invalid heap file"); munmap(base, map_size); flock(fd, LOCK_UN); close(fd); return NULL; |
|
370
|
2 |
6 |
if (fd >= 0) { flock(fd, LOCK_UN); close(fd); } |
|
375
|
7 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
376
|
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; } |
|
377
|
0 |
7 |
if (capacity > HEAP_MAX_CAPACITY) { HEAP_ERR("capacity too large (max %u)", (unsigned)HEAP_MAX_CAPACITY); return NULL; } |
|
|
0 |
0 |
if (capacity > HEAP_MAX_CAPACITY) { HEAP_ERR("capacity too large (max %u)", (unsigned)HEAP_MAX_CAPACITY); return NULL; } |
|
378
|
0 |
7 |
if (capacity > (UINT64_MAX - sizeof(HeapHeader)) / sizeof(HeapEntry)) { |
|
379
|
0 |
0 |
HEAP_ERR("capacity overflow"); return NULL; |
|
382
|
7 |
0 |
int fd = memfd_create(name ? name : "heap", MFD_CLOEXEC | MFD_ALLOW_SEALING); |
|
383
|
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; } |
|
384
|
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; } |
|
387
|
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; } |
|
393
|
1 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
395
|
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; } |
|
396
|
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; } |
|
399
|
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; } |
|
400
|
0 |
1 |
if (!heap_validate_header((HeapHeader *)base, (uint64_t)st.st_size)) { |
|
401
|
0 |
0 |
HEAP_ERR("invalid heap"); munmap(base, ms); return NULL; |
|
404
|
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; } |
|
409
|
0 |
17 |
if (!h) return; |
|
410
|
2 |
15 |
if (h->notify_fd >= 0) close(h->notify_fd); |
|
411
|
8 |
9 |
if (h->backing_fd >= 0) close(h->backing_fd); |
|
412
|
17 |
0 |
if (h->hdr) munmap(h->hdr, h->mmap_size); |
|
422
|
0 |
3 |
if (__atomic_load_n(&h->hdr->waiters_pop, __ATOMIC_RELAXED) > 0) |
|
427
|
0 |
2 |
if (h->notify_fd >= 0) return h->notify_fd; |
|
429
|
0 |
2 |
if (efd < 0) return -1; |
|
433
|
0 |
2 |
if (h->notify_fd < 0) return 0; |
|
437
|
0 |
2 |
if (h->notify_fd < 0) return -1; |
|
439
|
0 |
2 |
if (read(h->notify_fd, &v, sizeof(v)) != sizeof(v)) return -1; |