contributed by < yaohwang99
>
Aligned to the size of cache line for cache friendly code.
ifring
ringsz
is rounded up to power of 2, therefore we can use mask to calculate modulo.ring[i]
is i - ringsz
, for example, if ringsz is 8, then the indices are -8, -7, -6,…,-1.The enqueue steps can be summarized as the following:
neu
data.neu
to the ring, otherwise, move to next slot and repeat from step 1.At line 29, before(tail, __atomic_load_n(&lfr->head, __ATOMIC_ACQUIRE) + size)
checks if there are empty slots in the ring.
At line 39, (old.e.idx == tail - size)
if tail
is available, if not, then old.e.idx
should be equal to tail
if it is used by other producer recently.
cond_reload(tail, &lfr->tail)
returns the newest tail, either tail + 1
or lfr->tail
.
The dequeue steps can be summarized as the following:
elems[]
.lfr->head
, otherwise, update head
to the new lfr->head
and repeat from step 1.