[LAD] Atomic Operations

Arnold Krille arnold at arnoldarts.de
Tue Dec 15 20:05:44 UTC 2009


Hi,

On Tuesday 15 December 2009 19:33:18 Gabriel M. Beddingfield wrote:
> On Tue, 15 Dec 2009, Tim Blechmann wrote:
> >> http://github.com/radarsat1/dimple/blob/master/src/CircBuffer.h
> > you should add memory barriers, when reading or writing to the reader or
> Actually, his implementation is similar to ringbuffer.c in
> libjack... and assumes that reading and writing can happen
> atomically (as was pointed out by someone else) -- which can
> be managed with single reader / single writer
> requirement.[a]
> Unless I've misunderstood the code, ringbuffer.c is /not/
> using special atomic operations.

Why should a single-reader-single-writer ring-buffer need atomic operations?

The reader increments the read-pointer (which doesn't have to be a pointer) 
last when its finished, the writer increments the write-pointer last when it 
has written. All other access is read-only. No problems. (At least in my app.)

increment = read the old value, add one, modulo (or bit-mask) the size, write 
the new value

Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.linuxaudio.org/pipermail/linux-audio-dev/attachments/20091215/c48f5ea9/attachment.pgp>


More information about the Linux-audio-dev mailing list