Lines Matching refs:br

65 buf_ring_enqueue(struct buf_ring *br, void *buf)
70 for (i = br->br_cons_head; i != br->br_prod_head;
71 i = ((i + 1) & br->br_cons_mask))
72 if(br->br_ring[i] == buf)
74 buf, i, br->br_prod_tail, br->br_cons_tail);
78 prod_head = br->br_prod_head;
79 prod_next = (prod_head + 1) & br->br_prod_mask;
80 cons_tail = br->br_cons_tail;
84 if (prod_head == br->br_prod_head &&
85 cons_tail == br->br_cons_tail) {
86 br->br_drops++;
92 } while (!atomic_cmpset_acq_int(&br->br_prod_head, prod_head, prod_next));
94 if (br->br_ring[prod_head] != NULL)
97 br->br_ring[prod_head] = buf;
104 while (br->br_prod_tail != prod_head)
106 atomic_store_rel_int(&br->br_prod_tail, prod_next);
116 buf_ring_dequeue_mc(struct buf_ring *br)
123 cons_head = br->br_cons_head;
124 cons_next = (cons_head + 1) & br->br_cons_mask;
126 if (cons_head == br->br_prod_tail) {
130 } while (!atomic_cmpset_acq_int(&br->br_cons_head, cons_head, cons_next));
132 buf = br->br_ring[cons_head];
134 br->br_ring[cons_head] = NULL;
141 while (br->br_cons_tail != cons_head)
144 atomic_store_rel_int(&br->br_cons_tail, cons_next);
156 buf_ring_dequeue_sc(struct buf_ring *br)
178 * cons_head = br->br_cons_head;
179 * atomic_cmpset_acq_32(&br->br_prod_head, ...));
180 * buf = br->br_ring[cons_head]; <see <1>>
181 * br->br_ring[prod_head] = buf;
182 * atomic_store_rel_32(&br->br_prod_tail, ...);
183 * prod_tail = br->br_prod_tail;
188 * <1> Load (on core 1) from br->br_ring[cons_head] can be reordered (speculative readed) by CPU.
191 cons_head = atomic_load_acq_32(&br->br_cons_head);
193 cons_head = br->br_cons_head;
195 prod_tail = atomic_load_acq_32(&br->br_prod_tail);
197 cons_next = (cons_head + 1) & br->br_cons_mask;
199 cons_next_next = (cons_head + 2) & br->br_cons_mask;
207 prefetch(br->br_ring[cons_next]);
209 prefetch(br->br_ring[cons_next_next]);
212 br->br_cons_head = cons_next;
213 buf = br->br_ring[cons_head];
216 br->br_ring[cons_head] = NULL;
217 if (!mtx_owned(br->br_lock))
219 if (br->br_cons_tail != cons_head)
221 br->br_cons_tail, cons_head);
223 br->br_cons_tail = cons_next;
233 buf_ring_advance_sc(struct buf_ring *br)
238 cons_head = br->br_cons_head;
239 prod_tail = br->br_prod_tail;
241 cons_next = (cons_head + 1) & br->br_cons_mask;
244 br->br_cons_head = cons_next;
246 br->br_ring[cons_head] = NULL;
248 br->br_cons_tail = cons_next;
268 buf_ring_putback_sc(struct buf_ring *br, void *new)
270 KASSERT(br->br_cons_head != br->br_prod_tail,
272 br->br_ring[br->br_cons_head] = new;
281 buf_ring_peek(struct buf_ring *br)
285 if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
294 if (br->br_cons_head == br->br_prod_tail)
297 return (br->br_ring[br->br_cons_head]);
301 buf_ring_peek_clear_sc(struct buf_ring *br)
306 if (!mtx_owned(br->br_lock))
315 if (br->br_cons_head == br->br_prod_tail)
323 ret = br->br_ring[br->br_cons_head];
324 br->br_ring[br->br_cons_head] = NULL;
327 return (br->br_ring[br->br_cons_head]);
332 buf_ring_full(struct buf_ring *br)
335 return (((br->br_prod_head + 1) & br->br_prod_mask) == br->br_cons_tail);
339 buf_ring_empty(struct buf_ring *br)
342 return (br->br_cons_head == br->br_prod_tail);
346 buf_ring_count(struct buf_ring *br)
349 return ((br->br_prod_size + br->br_prod_tail - br->br_cons_tail)
350 & br->br_prod_mask);
355 void buf_ring_free(struct buf_ring *br, struct malloc_type *type);