Re: [linux-audio-dev] crossplatform atomics

From: Kai Vehmanen <kvehmanen@email-addr-hidden>
Date: Thu May 25 2006 - 19:57:55 EEST

On Wed, 24 May 2006, Paul Davis wrote:

>>> sizeof(int) is your friend
> not sure what you mean, but on sparcs, int writes are not atomic unless
> you only use the lower 24 bits.

Does someone have a good reference on this? I think the writes just are
not atomic, but you can use some tricks [1] to implement atomic behaviour
by spinning until the operation succeeds.

[1] http://www.freepatentsonline.com/5666546.html?highlight=5434995
     .. I'm not sure maybe this is just one variation...

But, reading the Linux 2.6.16.17 code for sparc (atomic.h and atomic.S),
only the writes are protected, not reads. So as long as you have only one
writer, you should be safe. Also, the 24bit limitation only applies if you
are using the low 8bits for spinning.

Anyways, a good (accurate and available online) reference for this would
be nice to have, to be 100% sure before making any architectural
decisions. For me, I'd be happy to just exclude these platforms, or use
mutexes as a crude workaround on the affected platforms (assuming there're
only few of them).

Cross-platform atomic integer operations would be nice, but you can do
quite a lot with just atomic read/writes, which most of the platforms
already provide for 'int's. For example, these are sufficient to implement
a simple one-writer-one-reader lock-free queue (which is necessary in most
audio apps).

OTOH, it is probably wise to explicitly mark all code where ints are
assumed to be atomic w.r.t. read/writes (or any other non-standard
properties). Especially if sparc-style atomic properties become more
widely used later on...

-- 
  links, my public keys, etc at http://eca.cx/kv
Received on Thu May 25 20:15:06 2006

This archive was generated by hypermail 2.1.8 : Thu May 25 2006 - 20:15:07 EEST