==========================
First of all, what is a circular buffer? A circular buffer is a buffer of
==========================
First of all, what is a circular buffer? A circular buffer is a buffer of
be careful, however, as a region more than one unit in size may wrap the end of
the buffer and be broken into two segments.
be careful, however, as a region more than one unit in size may wrap the end of
the buffer and be broken into two segments.
============================
Calculation of the occupancy or the remaining capacity of an arbitrarily sized
============================
Calculation of the occupancy or the remaining capacity of an arbitrarily sized
then a much quicker bitwise-AND instruction can be used instead.
Linux provides a set of macros for handling power-of-2 circular buffers. These
then a much quicker bitwise-AND instruction can be used instead.
Linux provides a set of macros for handling power-of-2 circular buffers. These
CIRC_CNT(head_index, tail_index, buffer_size);
This returns the number of items currently occupying a buffer[2].
CIRC_CNT(head_index, tail_index, buffer_size);
This returns the number of items currently occupying a buffer[2].
they will return a lower bound as the producer controls the head index,
but the consumer may still be depleting the buffer on another CPU and
moving the tail index.
they will return a lower bound as the producer controls the head index,
but the consumer may still be depleting the buffer on another CPU and
moving the tail index.
will return a lower bound as the consumer controls the tail index, but the
producer may still be filling the buffer on another CPU and moving the
head index.
will return a lower bound as the consumer controls the tail index, but the
producer may still be filling the buffer on another CPU and moving the
head index.
producer and consumer become visible cannot be guaranteed as they are
independent and may be made on different CPUs - so the result in such a
situation will merely be a guess, and may even be negative.
producer and consumer become visible cannot be guaranteed as they are
independent and may be made on different CPUs - so the result in such a
situation will merely be a guess, and may even be negative.
===========================================
By using memory barriers in conjunction with circular buffers, you can avoid
===========================================
By using memory barriers in conjunction with circular buffers, you can avoid