* multi-consumer safe dequeue * */
| 117 | * |
| 118 | */ |
| 119 | static __inline void * |
| 120 | buf_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 |
nothing calls this directly
no test coverage detected