[PATCH 2/4] Add atomic operations similar to those provided by C11.
Torvald Riegel
triegel@redhat.com
Wed Oct 29 21:50:00 GMT 2014
This patch adds atomic operations similar to C11.
The function naming is essentially the C11 names, but with the memory
order argument removed and added as a suffix. For example, C11's
atomic_store_explicit(&foo, 23, memory_order_release)
becomes
atomic_store_relaxed (&foo, 23);
This avoids naming collisions, and it's not much more verbose because we
would make the memory orders explicit anyway.
The provided functions are a subset of what C11 provides. I think it's
better to start minimal, as we can easily add more operations if needed.
I've chosen this subset based on the operations that would be necessary
for generic implementations of mutexes, pthread_once, rwlock,
semaphores, and condvars.
Likewise, I've chosen to only provide 32b atomics (which we need for
futexes, for example) and additionally 64b atomics if provided by the
arch (that's what __HAVE_64B_ATOMICS is for, see Patch 1/4).
Per Josephs request, attempts to apply atomic operations when using the
__atomic builtins to variables of other sizes results in an early error.
If not using the builtins, I rely on the existing atomics to Do The
Right Thing.
* include/atomic.h (__atomic_link_error, __atomic_check_size,
atomic_thread_fence_acquire, atomic_thread_fence_release,
atomic_thread_fence_seq_cst, atomic_load_relaxed,
atomic_load_acquire, atomic_store_relaxed, atomic_store_release,
atomic_compare_exchange_weak_relaxed,
atomic_compare_exchange_weak_acquire,
atomic_compare_exchange_weak_release,
atomic_exchange_acquire, atomic_exchange_release,
atomic_fetch_add_relaxed, atomic_fetch_add_acquire,
atomic_fetch_add_release, atomic_fetch_add_acq_rel,
atomic_fetch_and_acquire,
atomic_fetch_or_relaxed, atomic_fetch_or_acquire): New.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: atomic-ops.patch
Type: text/x-patch
Size: 9138 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20141029/fcb71c78/attachment.bin>
More information about the Libc-alpha
mailing list