| 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
|
46 |
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, |
|
127
|
0 |
46 |
if (__atomic_load_n(&hdr->mutex_waiters, __ATOMIC_RELAXED) > 0) |
|
140
|
19 |
12 |
while (idx > 0) { |
|
142
|
14 |
5 |
if (data[parent].priority <= data[idx].priority) break; |
|
153
|
5 |
6 |
if (left < size && data[left].priority < data[smallest].priority) |
|
|
4 |
1 |
if (left < size && data[left].priority < data[smallest].priority) |
|
155
|
2 |
9 |
if (right < size && data[right].priority < data[smallest].priority) |
|
|
1 |
1 |
if (right < size && data[right].priority < data[smallest].priority) |
|
157
|
7 |
4 |
if (smallest == idx) break; |
|
171
|
1 |
1 |
if (dl->tv_nsec >= 1000000000L) { dl->tv_sec++; dl->tv_nsec -= 1000000000L; } |
|
179
|
3 |
0 |
if (rem->tv_nsec < 0) { rem->tv_sec--; rem->tv_nsec += 1000000000L; } |
|
186
|
1 |
26 |
if (hdr->size >= (uint32_t)hdr->capacity) { |
|
197
|
0 |
26 |
if (__atomic_load_n(&hdr->waiters_pop, __ATOMIC_RELAXED) > 0) |
|
205
|
4 |
11 |
if (hdr->size == 0) { |
|
212
|
7 |
4 |
if (hdr->size > 0) { |
|
222
|
0 |
2 |
if (heap_pop(h, out_p, out_v)) return 1; |
|
223
|
0 |
2 |
if (timeout == 0) return 0; |
|
228
|
2 |
0 |
if (has_dl) heap_make_deadline(timeout, &dl); |
|
234
|
2 |
0 |
if (cur == 0) { |
|
236
|
2 |
0 |
if (has_dl) { |
|
237
|
0 |
2 |
if (!heap_remaining(&dl, &rem)) { |
|
247
|
1 |
1 |
if (heap_pop(h, out_p, out_v)) return 1; |
|
248
|
1 |
0 |
if (has_dl && !heap_remaining(&dl, &rem)) { |
|
|
1 |
0 |
if (has_dl && !heap_remaining(&dl, &rem)) { |
|
258
|
0 |
1 |
if (hdr->size == 0) { heap_mutex_unlock(hdr); return 0; } |
|
289
|
0 |
7 |
if (!h) { munmap(base, ms); return NULL; } |
|
293
|
3 |
4 |
h->path = path ? strdup(path) : NULL; |
|
300
|
5 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
301
|
0 |
5 |
if (capacity == 0) { HEAP_ERR("capacity must be > 0"); return NULL; } |
|
|
0 |
0 |
if (capacity == 0) { HEAP_ERR("capacity must be > 0"); return NULL; } |
|
302
|
0 |
5 |
if (capacity > (UINT64_MAX - sizeof(HeapHeader)) / sizeof(HeapEntry)) { |
|
303
|
0 |
0 |
HEAP_ERR("capacity overflow"); return NULL; |
|
312
|
2 |
3 |
if (anonymous) { |
|
315
|
0 |
2 |
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; } |
|
318
|
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; } |
|
319
|
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; } |
|
321
|
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; } |
|
323
|
2 |
1 |
if (is_new && ftruncate(fd, (off_t)total) < 0) { |
|
|
0 |
2 |
if (is_new && ftruncate(fd, (off_t)total) < 0) { |
|
324
|
0 |
0 |
HEAP_ERR("ftruncate: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; |
|
326
|
1 |
2 |
map_size = is_new ? (size_t)total : (size_t)st.st_size; |
|
328
|
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; } |
|
329
|
1 |
2 |
if (!is_new) { |
|
331
|
1 |
0 |
if (hdr->magic != HEAP_MAGIC || hdr->version != HEAP_VERSION || |
|
|
1 |
0 |
if (hdr->magic != HEAP_MAGIC || hdr->version != HEAP_VERSION || |
|
332
|
0 |
1 |
hdr->total_size != (uint64_t)st.st_size) { |
|
333
|
0 |
0 |
HEAP_ERR("invalid heap file"); munmap(base, map_size); flock(fd, LOCK_UN); close(fd); return NULL; |
|
340
|
2 |
2 |
if (fd >= 0) { flock(fd, LOCK_UN); close(fd); } |
|
345
|
1 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
346
|
0 |
1 |
if (capacity == 0) { HEAP_ERR("capacity must be > 0"); return NULL; } |
|
|
0 |
0 |
if (capacity == 0) { HEAP_ERR("capacity must be > 0"); return NULL; } |
|
347
|
0 |
1 |
if (capacity > (UINT64_MAX - sizeof(HeapHeader)) / sizeof(HeapEntry)) { |
|
348
|
0 |
0 |
HEAP_ERR("capacity overflow"); return NULL; |
|
351
|
1 |
0 |
int fd = memfd_create(name ? name : "heap", MFD_CLOEXEC); |
|
352
|
0 |
1 |
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; } |
|
353
|
0 |
1 |
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; } |
|
355
|
0 |
1 |
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; } |
|
361
|
1 |
0 |
if (errbuf) errbuf[0] = '\0'; |
|
363
|
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; } |
|
364
|
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; } |
|
367
|
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; } |
|
369
|
1 |
0 |
if (hdr->magic != HEAP_MAGIC || hdr->version != HEAP_VERSION || |
|
|
1 |
0 |
if (hdr->magic != HEAP_MAGIC || hdr->version != HEAP_VERSION || |
|
370
|
0 |
1 |
hdr->total_size != (uint64_t)st.st_size) { |
|
371
|
0 |
0 |
HEAP_ERR("invalid heap"); munmap(base, ms); return NULL; |
|
374
|
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; } |
|
379
|
0 |
7 |
if (!h) return; |
|
380
|
1 |
6 |
if (h->notify_fd >= 0) close(h->notify_fd); |
|
381
|
2 |
5 |
if (h->backing_fd >= 0) close(h->backing_fd); |
|
382
|
7 |
0 |
if (h->hdr) munmap(h->hdr, h->mmap_size); |
|
392
|
0 |
3 |
if (__atomic_load_n(&h->hdr->waiters_pop, __ATOMIC_RELAXED) > 0) |
|
397
|
0 |
1 |
if (h->notify_fd >= 0) close(h->notify_fd); |
|
399
|
0 |
1 |
if (efd < 0) return -1; |
|
403
|
0 |
1 |
if (h->notify_fd < 0) return 0; |
|
407
|
0 |
1 |
if (h->notify_fd < 0) return -1; |
|
409
|
0 |
1 |
if (read(h->notify_fd, &v, sizeof(v)) != sizeof(v)) return -1; |