aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/stdatomic.h
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2018-08-06 23:51:08 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2018-08-06 23:51:08 +0000
commitd2aec9714a3876e025a8235e7f347374c1e83d34 (patch)
tree36e40e3f94c5cd0497868e30962534d2df1eab50 /sys/sys/stdatomic.h
parent1979b5114125dc678c86b811aae396b8368b8b61 (diff)
downloadsrc-d2aec9714a3876e025a8235e7f347374c1e83d34.tar.gz
src-d2aec9714a3876e025a8235e7f347374c1e83d34.zip
Make the system C11 atomics headers fully compatible with external GCC.
The <sys/cdefs.h> and <stdatomic.h> headers already included support for C11 atomics via intrinsincs in modern versions of GCC, but these versions tried to "hide" atomic variables inside a wrapper structure. This wrapper is not compatible with GCC's internal <stdatomic.h> header, so that if GCC's <stdatomic.h> was used together with <sys/cdefs.h>, use of C11 atomics would fail to compile. Fix this by not hiding atomic variables in a structure for modern versions of GCC. The headers already avoid using a wrapper structure on clang. Note that this wrapper was only used if C11 was not enabled (e.g. via -std=c99), so this also fixes compile failures if a modern version of GCC was used with -std=c11 but with FreeBSD's <stdatomic.h> instead of GCC's <stdatomic.h> and this change fixes that case as well. Reported by: Mark Millard Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D16585
Notes
Notes: svn path=/head/; revision=337399
Diffstat (limited to 'sys/sys/stdatomic.h')
-rw-r--r--sys/sys/stdatomic.h25
1 files changed, 11 insertions, 14 deletions
diff --git a/sys/sys/stdatomic.h b/sys/sys/stdatomic.h
index 94b69befb7b8..cac36fa6adf6 100644
--- a/sys/sys/stdatomic.h
+++ b/sys/sys/stdatomic.h
@@ -171,12 +171,9 @@ atomic_signal_fence(memory_order __order __unused)
/* Atomics in kernelspace are always lock-free. */
#define atomic_is_lock_free(obj) \
((void)(obj), (_Bool)1)
-#elif defined(__CLANG_ATOMICS)
+#elif defined(__CLANG_ATOMICS) || defined(__GNUC_ATOMICS)
#define atomic_is_lock_free(obj) \
__atomic_is_lock_free(sizeof(*(obj)), obj)
-#elif defined(__GNUC_ATOMICS)
-#define atomic_is_lock_free(obj) \
- __atomic_is_lock_free(sizeof((obj)->__val), &(obj)->__val)
#else
#define atomic_is_lock_free(obj) \
((void)(obj), sizeof((obj)->__val) <= sizeof(void *))
@@ -260,28 +257,28 @@ typedef _Atomic(__uintmax_t) atomic_uintmax_t;
#elif defined(__GNUC_ATOMICS)
#define atomic_compare_exchange_strong_explicit(object, expected, \
desired, success, failure) \
- __atomic_compare_exchange_n(&(object)->__val, expected, \
+ __atomic_compare_exchange_n(object, expected, \
desired, 0, success, failure)
#define atomic_compare_exchange_weak_explicit(object, expected, \
desired, success, failure) \
- __atomic_compare_exchange_n(&(object)->__val, expected, \
+ __atomic_compare_exchange_n(object, expected, \
desired, 1, success, failure)
#define atomic_exchange_explicit(object, desired, order) \
- __atomic_exchange_n(&(object)->__val, desired, order)
+ __atomic_exchange_n(object, desired, order)
#define atomic_fetch_add_explicit(object, operand, order) \
- __atomic_fetch_add(&(object)->__val, operand, order)
+ __atomic_fetch_add(object, operand, order)
#define atomic_fetch_and_explicit(object, operand, order) \
- __atomic_fetch_and(&(object)->__val, operand, order)
+ __atomic_fetch_and(object, operand, order)
#define atomic_fetch_or_explicit(object, operand, order) \
- __atomic_fetch_or(&(object)->__val, operand, order)
+ __atomic_fetch_or(object, operand, order)
#define atomic_fetch_sub_explicit(object, operand, order) \
- __atomic_fetch_sub(&(object)->__val, operand, order)
+ __atomic_fetch_sub(object, operand, order)
#define atomic_fetch_xor_explicit(object, operand, order) \
- __atomic_fetch_xor(&(object)->__val, operand, order)
+ __atomic_fetch_xor(object, operand, order)
#define atomic_load_explicit(object, order) \
- __atomic_load_n(&(object)->__val, order)
+ __atomic_load_n(object, order)
#define atomic_store_explicit(object, desired, order) \
- __atomic_store_n(&(object)->__val, desired, order)
+ __atomic_store_n(object, desired, order)
#else
#define __atomic_apply_stride(object, operand) \
(((__typeof__((object)->__val))0) + (operand))