Coverage Report

Created: 2025-12-14 06:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bind9/lib/isc/include/isc/queue.h
Line
Count
Source
1
/*
2
 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3
 *
4
 * SPDX-License-Identifier: MPL-2.0
5
 *
6
 * This Source Code Form is subject to the terms of the Mozilla Public
7
 * License, v. 2.0. If a copy of the MPL was not distributed with this
8
 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
9
 *
10
 * See the COPYRIGHT file distributed with this work for additional
11
 * information regarding copyright ownership.
12
 */
13
14
#include <isc/os.h>
15
#include <isc/urcu.h>
16
17
STATIC_ASSERT(sizeof(struct __cds_wfcq_head) <= ISC_OS_CACHELINE_SIZE,
18
        "size of struct __cds_wfcq_head must be smaller than "
19
        "ISC_OS_CACHELINE_SIZE");
20
21
typedef struct isc_queue {
22
  struct __cds_wfcq_head head;
23
  uint8_t          __padding_head[ISC_OS_CACHELINE_SIZE -
24
              sizeof(struct __cds_wfcq_head)];
25
  struct cds_wfcq_tail   tail;
26
  uint8_t          __padding_tail[ISC_OS_CACHELINE_SIZE -
27
              sizeof(struct __cds_wfcq_head)];
28
} isc_queue_t;
29
30
typedef struct cds_wfcq_node isc_queue_node_t;
31
32
static inline void
33
0
isc_queue_node_init(isc_queue_node_t *node) {
34
0
  cds_wfcq_node_init(node);
35
0
}
36
37
static inline void
38
0
isc_queue_init(isc_queue_t *queue) {
39
0
  __cds_wfcq_init(&(queue)->head, &(queue)->tail);
40
0
}
41
42
static inline void
43
0
isc_queue_destroy(isc_queue_t *queue) {
44
0
  UNUSED(queue);
45
0
}
46
47
static inline bool
48
0
isc_queue_empty(isc_queue_t *queue) {
49
0
  return cds_wfcq_empty(&(queue)->head, &(queue)->tail);
50
0
}
51
52
static inline bool
53
0
isc_queue_enqueue(isc_queue_t *queue, isc_queue_node_t *node) {
54
0
  return cds_wfcq_enqueue(&(queue)->head, &(queue)->tail, node);
55
0
}
56
57
#define isc_queue_enqueue_entry(queue, entry, member) \
58
0
  cds_wfcq_enqueue(&(queue)->head, &(queue)->tail, &((entry)->member))
59
60
static inline isc_queue_node_t *
61
0
isc_queue_dequeue(isc_queue_t *queue) {
62
0
  return __cds_wfcq_dequeue_nonblocking(&(queue)->head, &(queue)->tail);
63
0
}
64
65
#define isc_queue_entry(ptr, type, member) \
66
0
  caa_container_of_check_null(ptr, type, member)
67
68
#define isc_queue_dequeue_entry(queue, type, member) \
69
  isc_queue_entry(isc_queue_dequeue(queue), type, member)
70
71
static inline bool
72
0
isc_queue_splice(isc_queue_t *dest, isc_queue_t *src) {
73
0
  enum cds_wfcq_ret ret = __cds_wfcq_splice_blocking(
74
0
    &dest->head, &dest->tail, &src->head, &src->tail);
75
0
  INSIST(ret != CDS_WFCQ_RET_WOULDBLOCK &&
76
0
         ret != CDS_WFCQ_RET_DEST_NON_EMPTY);
77
78
0
  return ret != CDS_WFCQ_RET_SRC_EMPTY;
79
0
}
80
81
#define isc_queue_first_entry(queue, type, member)                         \
82
0
  isc_queue_entry(                                                   \
83
0
    __cds_wfcq_first_blocking(&(queue)->head, &(queue)->tail), \
84
0
    type, member)
85
86
#define isc_queue_next_entry(queue, node, type, member)                 \
87
0
  isc_queue_entry(__cds_wfcq_next_blocking(&(queue)->head,        \
88
0
             &(queue)->tail, node), \
89
0
      type, member)
90
91
#define isc_queue_for_each_entry(queue, pos, member)                       \
92
  for (pos = isc_queue_first_entry(queue, __typeof__(*pos), member); \
93
       pos != NULL;                                                  \
94
       pos = isc_queue_next_entry(queue, &(pos)->member,             \
95
          __typeof__(*pos), member))
96
97
#define isc_queue_for_each_entry_safe(queue, pos, next, member)            \
98
0
  for (pos = isc_queue_first_entry(queue, __typeof__(*pos), member), \
99
0
      next = (pos ? isc_queue_next_entry(queue, &(pos)->member,      \
100
0
                 __typeof__(*pos), member)   \
101
0
      : NULL);                                           \
102
0
       pos != NULL; pos = next,                                      \
103
0
      next = (pos ? isc_queue_next_entry(queue, &(pos)->member,      \
104
0
                 __typeof__(*pos), member)   \
105
0
      : NULL))