From 3315a037247cd7f468d5bd863c52230d05548dcd Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Mon, 4 Apr 2016 09:58:22 +0300 Subject: Define AO_TS_SET as __GCC_ATOMIC_TEST_AND_SET_TRUEVAL if applicable * src/atomic_ops/sysdeps/gcc/aarch64.h (AO_GCC_ATOMIC_TEST_AND_SET): Define (before include test_and_set_t_is_ao_t.h). * src/atomic_ops/sysdeps/gcc/nios2.h (AO_GCC_ATOMIC_TEST_AND_SET): Likewise. * src/atomic_ops/sysdeps/test_and_set_t_is_ao_t.h: Refine comment. * src/atomic_ops/sysdeps/test_and_set_t_is_char.h: Likewise. * src/atomic_ops/sysdeps/test_and_set_t_is_ao_t.h (AO_TS_SET_TRUEVAL): New internal macro (defined via __GCC_ATOMIC_TEST_AND_SET_TRUEVAL). * src/atomic_ops/sysdeps/test_and_set_t_is_char.h (AO_TS_SET_TRUEVAL): Likewise. * src/atomic_ops/sysdeps/test_and_set_t_is_ao_t.h (AO_TS_val): Use AO_TS_SET_TRUEVAL instead of 1. * src/atomic_ops/sysdeps/test_and_set_t_is_char.h (AO_BYTE_TS_val): Use AO_TS_SET_TRUEVAL instead of 0xff; reformat code. * src/atomic_ops/sysdeps/test_and_set_t_is_char.h (AO_TS_t): Move down (to be after AO_TS_SET). --- src/atomic_ops/sysdeps/gcc/aarch64.h | 1 + src/atomic_ops/sysdeps/gcc/nios2.h | 2 ++ src/atomic_ops/sysdeps/test_and_set_t_is_ao_t.h | 13 ++++++++++--- src/atomic_ops/sysdeps/test_and_set_t_is_char.h | 18 +++++++++++++++--- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/atomic_ops/sysdeps/gcc/aarch64.h b/src/atomic_ops/sysdeps/gcc/aarch64.h index 612bc18..d3508a6 100644 --- a/src/atomic_ops/sysdeps/gcc/aarch64.h +++ b/src/atomic_ops/sysdeps/gcc/aarch64.h @@ -15,6 +15,7 @@ * */ +#define AO_GCC_ATOMIC_TEST_AND_SET #include "../test_and_set_t_is_ao_t.h" #include "../standard_ao_double_t.h" diff --git a/src/atomic_ops/sysdeps/gcc/nios2.h b/src/atomic_ops/sysdeps/gcc/nios2.h index f402cbb..a7f2ef8 100644 --- a/src/atomic_ops/sysdeps/gcc/nios2.h +++ b/src/atomic_ops/sysdeps/gcc/nios2.h @@ -11,7 +11,9 @@ * modified is included with the above copyright notice. */ +#define AO_GCC_ATOMIC_TEST_AND_SET #include "../test_and_set_t_is_ao_t.h" + #include "generic.h" #define AO_T_IS_INT diff --git a/src/atomic_ops/sysdeps/test_and_set_t_is_ao_t.h b/src/atomic_ops/sysdeps/test_and_set_t_is_ao_t.h index 606f7ac..d05f498 100644 --- a/src/atomic_ops/sysdeps/test_and_set_t_is_ao_t.h +++ b/src/atomic_ops/sysdeps/test_and_set_t_is_ao_t.h @@ -23,10 +23,17 @@ /* * These are common definitions for architectures on which test_and_set * operates on pointer-sized quantities, the "clear" value contains - * all zeroes, and the "set" value contains only one lowest bit set. - * This can be used if test_and_set is synthesized from compare_and_swap. + * all zeroes, and the "set" value contains only one lowest bit set typically. */ -typedef enum {AO_TS_clear = 0, AO_TS_set = 1} AO_TS_val; + +#if defined(AO_GCC_ATOMIC_TEST_AND_SET) && !defined(AO_PREFER_GENERALIZED) \ + && defined(__GCC_ATOMIC_TEST_AND_SET_TRUEVAL) +# define AO_TS_SET_TRUEVAL __GCC_ATOMIC_TEST_AND_SET_TRUEVAL +#else +# define AO_TS_SET_TRUEVAL 1 +#endif + +typedef enum { AO_TS_clear = 0, AO_TS_set = AO_TS_SET_TRUEVAL } AO_TS_val; #define AO_TS_VAL_t AO_TS_val #define AO_TS_CLEAR AO_TS_clear #define AO_TS_SET AO_TS_set diff --git a/src/atomic_ops/sysdeps/test_and_set_t_is_char.h b/src/atomic_ops/sysdeps/test_and_set_t_is_char.h index 8e265aa..1711ffd 100644 --- a/src/atomic_ops/sysdeps/test_and_set_t_is_char.h +++ b/src/atomic_ops/sysdeps/test_and_set_t_is_char.h @@ -23,13 +23,25 @@ /* * These are common definitions for architectures on which test_and_set * operates on byte sized quantities, the "clear" value contains - * all zeroes, and the "set" value contains all ones. + * all zeroes, and the "set" value contains all ones typically. */ -#define AO_TS_t unsigned char -typedef enum {AO_BYTE_TS_clear = 0, AO_BYTE_TS_set = 0xff} AO_BYTE_TS_val; +#if defined(AO_GCC_ATOMIC_TEST_AND_SET) && !defined(AO_PREFER_GENERALIZED) \ + && defined(__GCC_ATOMIC_TEST_AND_SET_TRUEVAL) +# define AO_TS_SET_TRUEVAL __GCC_ATOMIC_TEST_AND_SET_TRUEVAL +#else +# define AO_TS_SET_TRUEVAL 0xff +#endif + +typedef enum { + AO_BYTE_TS_clear = 0, + AO_BYTE_TS_set = AO_TS_SET_TRUEVAL +} AO_BYTE_TS_val; + #define AO_TS_VAL_t AO_BYTE_TS_val #define AO_TS_CLEAR AO_BYTE_TS_clear #define AO_TS_SET AO_BYTE_TS_set +#define AO_TS_t unsigned char + #define AO_CHAR_TS_T 1 -- cgit v1.2.1