[linux-audio-dev] lock-free ring buffer code

Steve Harris S.W.Harris at ecs.soton.ac.uk
Fri Apr 4 08:30:01 UTC 2003

On Fri, Apr 04, 2003 at 07:48:20 -0500, Paul Davis wrote:
> there is one aspect of the LFRB that bothers me. as has been explained
> many times, the monotonic motion of the read/write pointers is
> key. but when one the reader/writer moves the pointer to the end of
> the buffer and wraps it around, that operation does not cause
> monotonic motion (its semantically monotonic, but in fact the pointer
> value goes from high to low). i've never quite satisfied myself that
> this is threadsafe.

I think its fine because the addressing technique of the ringbuffer is that
the address is evaluated by masking the pointer offset number, and this is
true for every access (tecnically speaking, obviously you dont always have
to perform the mask).

The behaviour is also correct if you address backwards (as in a FIR
filters ringbuffer, ie. back in time).

Of course this is only true if the buffer is power-of-two sized.

- Steve

More information about the Linux-audio-dev mailing list