Branch Coverage

deque.h
Criterion Covered Total %
branch 102 218 46.7


line true false branch
78 1 4 if (dl->tv_nsec >= 1000000000L) { dl->tv_sec++; dl->tv_nsec -= 1000000000L; }
86 6 3 if (rem->tv_nsec < 0) { rem->tv_sec--; rem->tv_nsec += 1000000000L; }
109 3 43 if (t - hd >= hdr->capacity) return 0;
110 43 0 if (__atomic_compare_exchange_n(&hdr->tail, &t, t + 1,
115 0 43 if (cp < sz) memset(deq_slot(h, t) + cp, 0, sz - cp);
118 0 43 if (__atomic_load_n(&hdr->waiters_pop, __ATOMIC_RELAXED) > 0)
134 3 7 if (t - hd >= hdr->capacity) return 0;
136 7 0 if (__atomic_compare_exchange_n(&hdr->head, &hd, new_hd,
141 0 7 if (cp < sz) memset(deq_slot(h, new_hd) + cp, 0, sz - cp);
144 0 7 if (__atomic_load_n(&hdr->waiters_pop, __ATOMIC_RELAXED) > 0)
160 4 11 if (t - hd == 0) return 0;
161 11 0 if (__atomic_compare_exchange_n(&hdr->head, &hd, hd + 1,
165 0 11 if (__atomic_load_n(&hdr->waiters_push, __ATOMIC_RELAXED) > 0)
181 3 8 if (t - hd == 0) return 0;
182 8 0 if (__atomic_compare_exchange_n(&hdr->tail, &t, t - 1,
186 0 8 if (__atomic_load_n(&hdr->waiters_push, __ATOMIC_RELAXED) > 0)
200 1 1 front ? deq_try_push_front : deq_try_push_back;
201 0 2 if (try_fn(h, val, vlen)) return 1;
202 0 2 if (timeout == 0) return 0;
207 2 0 if (has_dl) deq_make_deadline(timeout, &dl);
214 2 0 if (t - hd >= hdr->capacity) {
216 2 0 if (has_dl) {
217 0 2 if (!deq_remaining(&dl, &rem)) {
228 0 2 if (try_fn(h, val, vlen)) return 1;
229 2 0 if (has_dl && !deq_remaining(&dl, &rem)) {
2 0 if (has_dl && !deq_remaining(&dl, &rem)) {
238 1 2 back ? deq_try_pop_back : deq_try_pop_front;
239 0 3 if (try_fn(h, out)) return 1;
240 0 3 if (timeout == 0) return 0;
245 3 0 if (has_dl) deq_make_deadline(timeout, &dl);
252 3 0 if (t - hd == 0) {
254 3 0 if (has_dl) {
255 0 3 if (!deq_remaining(&dl, &rem)) {
266 1 2 if (try_fn(h, out)) return 1;
267 2 0 if (has_dl && !deq_remaining(&dl, &rem)) {
2 0 if (has_dl && !deq_remaining(&dl, &rem)) {
298 0 7 if (!h) { munmap(base, ms); return NULL; }
303 3 4 h->path = path ? strdup(path) : NULL;
312 5 0 if (errbuf) errbuf[0] = '\0';
313 0 5 if (capacity == 0) { DEQ_ERR("capacity must be > 0"); return NULL; }
0 0 if (capacity == 0) { DEQ_ERR("capacity must be > 0"); return NULL; }
314 0 5 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; }
315 0 5 if (capacity > (UINT64_MAX - sizeof(DeqHeader)) / elem_size) {
316 0 0 DEQ_ERR("capacity * elem_size overflow"); return NULL;
325 2 3 if (anonymous) {
328 0 2 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; }
331 0 3 if (fd < 0) { DEQ_ERR("open: %s", strerror(errno)); return NULL; }
0 0 if (fd < 0) { DEQ_ERR("open: %s", strerror(errno)); return NULL; }
332 0 3 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; }
334 0 3 if (fstat(fd, &st) < 0) {
335 0 0 DEQ_ERR("fstat: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL;
338 2 1 if (is_new && ftruncate(fd, (off_t)total) < 0) {
0 2 if (is_new && ftruncate(fd, (off_t)total) < 0) {
339 0 0 DEQ_ERR("ftruncate: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL;
341 1 2 map_size = is_new ? (size_t)total : (size_t)st.st_size;
343 0 3 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; }
344 1 2 if (!is_new) {
346 1 0 if (hdr->magic != DEQ_MAGIC || hdr->version != DEQ_VERSION ||
1 0 if (hdr->magic != DEQ_MAGIC || hdr->version != DEQ_VERSION ||
347 1 0 hdr->variant_id != variant_id ||
348 0 1 hdr->total_size != (uint64_t)st.st_size) {
349 0 0 DEQ_ERR("invalid deque file"); munmap(base, map_size); flock(fd, LOCK_UN); close(fd); return NULL;
356 2 2 if (fd >= 0) { flock(fd, LOCK_UN); close(fd); }
363 1 0 if (errbuf) errbuf[0] = '\0';
364 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; }
365 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; }
366 0 1 if (capacity > (UINT64_MAX - sizeof(DeqHeader)) / elem_size) {
367 0 0 DEQ_ERR("capacity * elem_size overflow"); return NULL;
370 1 0 int fd = memfd_create(name ? name : "deque", MFD_CLOEXEC);
371 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; }
372 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; }
374 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; }
380 1 0 if (errbuf) errbuf[0] = '\0';
382 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; }
383 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; }
386 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; }
388 1 0 if (hdr->magic != DEQ_MAGIC || hdr->version != DEQ_VERSION ||
1 0 if (hdr->magic != DEQ_MAGIC || hdr->version != DEQ_VERSION ||
389 1 0 hdr->variant_id != variant_id ||
390 0 1 hdr->total_size != (uint64_t)st.st_size) {
391 0 0 DEQ_ERR("invalid deque"); munmap(base, ms); return NULL;
394 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; }
399 0 7 if (!h) return;
400 1 6 if (h->notify_fd >= 0) close(h->notify_fd);
401 2 5 if (h->backing_fd >= 0) close(h->backing_fd);
402 7 0 if (h->hdr) munmap(h->hdr, h->mmap_size);
411 0 3 if (__atomic_load_n(&h->hdr->waiters_push, __ATOMIC_RELAXED) > 0)
413 0 3 if (__atomic_load_n(&h->hdr->waiters_pop, __ATOMIC_RELAXED) > 0)
424 0 0 if (count == 0) return 0;
425 0 0 if (__atomic_compare_exchange_n(&hdr->head, &hd, t,
427 0 0 if (__atomic_load_n(&hdr->waiters_push, __ATOMIC_RELAXED) > 0)
435 0 1 if (h->notify_fd >= 0) close(h->notify_fd);
437 0 1 if (efd < 0) return -1;
441 0 1 if (h->notify_fd < 0) return 0;
445 0 1 if (h->notify_fd < 0) return -1;
447 0 1 if (read(h->notify_fd, &v, sizeof(v)) != sizeof(v)) return -1;