From: Ivan Maidanski Date: Wed, 2 Jan 2013 09:40:21 +0000 (+0400) Subject: Add missing generalization of no-barrier CAS in template X-Git-Tag: libatomic_ops-7_4_0~54 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6b1f5ae26745ad847ca33b713f21dcda3a41838c;p=libatomic_ops Add missing generalization of no-barrier CAS in template * src/atomic_ops/generalize-small.template (AO_XSIZE_compare_and_swap): Add missed definition (based on AO_XSIZE_fetch_compare_and_swap). * src/atomic_ops/generalize-small.template (AO_XSIZE_fetch_and_add_full): Add comment (copy from generalize.h). * src/atomic_ops/generalize-small.h: Regenerate. --- diff --git a/src/atomic_ops/generalize-small.h b/src/atomic_ops/generalize-small.h index 44d16ff..3dfc18b 100644 --- a/src/atomic_ops/generalize-small.h +++ b/src/atomic_ops/generalize-small.h @@ -193,7 +193,20 @@ # define AO_HAVE_char_compare_and_swap_release #endif +#if defined(AO_HAVE_char_fetch_compare_and_swap) \ + && !defined(AO_HAVE_char_compare_and_swap) + AO_INLINE int + AO_char_compare_and_swap(volatile unsigned/**/char *addr, unsigned/**/char old_val, + unsigned/**/char new_val) + { + return AO_char_fetch_compare_and_swap(addr, old_val, new_val) == old_val; + } +# define AO_HAVE_char_compare_and_swap +#endif + /* char_fetch_and_add */ +/* We first try to implement fetch_and_add variants in terms of the */ +/* corresponding compare_and_swap variants to minimize adding barriers. */ #if defined(AO_HAVE_char_compare_and_swap_full) \ && !defined(AO_HAVE_char_fetch_and_add_full) AO_INLINE unsigned/**/char @@ -836,7 +849,20 @@ # define AO_HAVE_short_compare_and_swap_release #endif +#if defined(AO_HAVE_short_fetch_compare_and_swap) \ + && !defined(AO_HAVE_short_compare_and_swap) + AO_INLINE int + AO_short_compare_and_swap(volatile unsigned/**/short *addr, unsigned/**/short old_val, + unsigned/**/short new_val) + { + return AO_short_fetch_compare_and_swap(addr, old_val, new_val) == old_val; + } +# define AO_HAVE_short_compare_and_swap +#endif + /* short_fetch_and_add */ +/* We first try to implement fetch_and_add variants in terms of the */ +/* corresponding compare_and_swap variants to minimize adding barriers. */ #if defined(AO_HAVE_short_compare_and_swap_full) \ && !defined(AO_HAVE_short_fetch_and_add_full) AO_INLINE unsigned/**/short @@ -1479,7 +1505,20 @@ # define AO_HAVE_int_compare_and_swap_release #endif +#if defined(AO_HAVE_int_fetch_compare_and_swap) \ + && !defined(AO_HAVE_int_compare_and_swap) + AO_INLINE int + AO_int_compare_and_swap(volatile unsigned *addr, unsigned old_val, + unsigned new_val) + { + return AO_int_fetch_compare_and_swap(addr, old_val, new_val) == old_val; + } +# define AO_HAVE_int_compare_and_swap +#endif + /* int_fetch_and_add */ +/* We first try to implement fetch_and_add variants in terms of the */ +/* corresponding compare_and_swap variants to minimize adding barriers. */ #if defined(AO_HAVE_int_compare_and_swap_full) \ && !defined(AO_HAVE_int_fetch_and_add_full) AO_INLINE unsigned diff --git a/src/atomic_ops/generalize-small.template b/src/atomic_ops/generalize-small.template index 5f5bb9a..b56430e 100644 --- a/src/atomic_ops/generalize-small.template +++ b/src/atomic_ops/generalize-small.template @@ -193,7 +193,20 @@ # define AO_HAVE_XSIZE_compare_and_swap_release #endif +#if defined(AO_HAVE_XSIZE_fetch_compare_and_swap) \ + && !defined(AO_HAVE_XSIZE_compare_and_swap) + AO_INLINE int + AO_XSIZE_compare_and_swap(volatile XCTYPE *addr, XCTYPE old_val, + XCTYPE new_val) + { + return AO_XSIZE_fetch_compare_and_swap(addr, old_val, new_val) == old_val; + } +# define AO_HAVE_XSIZE_compare_and_swap +#endif + /* XSIZE_fetch_and_add */ +/* We first try to implement fetch_and_add variants in terms of the */ +/* corresponding compare_and_swap variants to minimize adding barriers. */ #if defined(AO_HAVE_XSIZE_compare_and_swap_full) \ && !defined(AO_HAVE_XSIZE_fetch_and_add_full) AO_INLINE XCTYPE