I am looking for a good set of portable, supported atomic.h-style
primitives for userspace applications. I am not especially interested
in the low-level functions defined in <asm/atomic.h>. I really want
something more powerful like the kernel's compare_and_swap(),
cmpxchg(), test_and_set(), atomic_inc_and_return(), or fetch_and_add()
primitives. My intuition is that almost everything of interest could
be programmed out with a good compare_and_swap() or cmpxchg()
implementation.
These should work on most hardware platforms and operating systems, at
least as many as are possible and practical. They should work well
with both multithreaded UP and SMP. They need to work across multiple
process address spaces with shared memory. I would normally want to
avoid releasing different application binaries for UP and SMP.
They should be realtime-safe, which means that programming things out
using posix_spin_lock(), etc., is probably not good enough, except
perhaps as a generic solution to handle hard-to-support platforms.
While my needs are not unique to Linux audio, many audio applications
probably share them. So, I wonder what other people here on LAD are
doing.
All I've found so far are...
(*) kernel implementations of <asm/atomic.h> and <asm/system.h>.
These were written for kernel use, though some also work in
userspace. At least most platforms are probably fairly well
tested.
But, I prefer to avoid using kernel header files in application
code, mostly for portability and maintenance reasons.
Distributions handle them in non-standard ways, making it hard
to explain to users how to resolve the dependency. Also,
porting to non-Linux platforms becomes problematic.
(*) glibc seems to have a good set of functions internally
AFAICT, these are for the library's own use, not part of the
supported external interface. I'll investigate further.
(*) ardour has its own <pbd/atomic.h>
This does not seem to be well tested yet. But, a recent patch
by Robert Jordens at least makes it compile correctly on all the
Debian platforms using #ifdef's. Since the code was taken
directly from kernel sources, it is even likely to work on most
of those platforms (if compiled correctly).
(*) ardour has a ring queue implementation in ringbuffer.cc
There is also a C version included in the JACK example-clients
directory. These are excellent for some problems, but certainly
not for everything.
Advice or comments?
--
Jack O'Quin
Austin, Texas, USA