MCPcopy Create free account
hub / github.com/F-Stack/f-stack / buf_ring_dequeue_mc

Function buf_ring_dequeue_mc

freebsd/sys/buf_ring.h:119–152  ·  view source on GitHub ↗

* multi-consumer safe dequeue * */

Source from the content-addressed store, hash-verified

117 *
118 */
119static __inline void *
120buf_ring_dequeue_mc(struct buf_ring *br)
121{
122 uint32_t cons_head, cons_next;
123 void *buf;
124
125 critical_enter();
126 do {
127 cons_head = br->br_cons_head;
128 cons_next = (cons_head + 1) & br->br_cons_mask;
129
130 if (cons_head == br->br_prod_tail) {
131 critical_exit();
132 return (NULL);
133 }
134 } while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next));
135
136 buf = br->br_ring[cons_head];
137#ifdef DEBUG_BUFRING
138 br->br_ring[cons_head] = NULL;
139#endif
140 /*
141 * If there are other dequeues in progress
142 * that preceded us, we need to wait for them
143 * to complete
144 */
145 while (br->br_cons_tail != cons_head)
146 cpu_spinwait();
147
148 atomic_store_rel_int(&br->br_cons_tail, cons_next);
149 critical_exit();
150
151 return (buf);
152}
153
154/*
155 * single-consumer dequeue

Callers

nothing calls this directly

Calls 2

critical_enterFunction · 0.70
critical_exitFunction · 0.70

Tested by

no test coverage detected