From 07ada9bb18fdee939cb7d1add4d5bfa11a6c4d09 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Sat, 12 Jan 2013 23:55:52 +0400 Subject: [PATCH] Add AO_double_store pthread-based implementation and tests * src/atomic_ops/sysdeps/generic_pthread.h (AO_double_store_full): New primitive. * tests/test_atomic_include.template (test_atomicXX): Add test of AO_double_storeXX. --- src/atomic_ops/sysdeps/generic_pthread.h | 10 ++++++++++ tests/test_atomic_include.template | 21 ++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/atomic_ops/sysdeps/generic_pthread.h b/src/atomic_ops/sysdeps/generic_pthread.h index 54761eb..3c65624 100644 --- a/src/atomic_ops/sysdeps/generic_pthread.h +++ b/src/atomic_ops/sysdeps/generic_pthread.h @@ -383,6 +383,16 @@ AO_double_load_full(const volatile AO_double_t *addr) } #define AO_HAVE_double_load_full +AO_INLINE void +AO_double_store_full(volatile AO_double_t *addr, AO_double_t value) +{ + pthread_mutex_lock(&AO_pt_lock); + addr->AO_val1 = value.AO_val1; + addr->AO_val2 = value.AO_val2; + pthread_mutex_unlock(&AO_pt_lock); +} +#define AO_HAVE_double_store_full + AO_INLINE int AO_compare_double_and_swap_double_full(volatile AO_double_t *addr, AO_t old1, AO_t old2, diff --git a/tests/test_atomic_include.template b/tests/test_atomic_include.template index ea6fd9d..60068b5 100644 --- a/tests/test_atomic_include.template +++ b/tests/test_atomic_include.template @@ -26,7 +26,8 @@ void test_atomicXX(void) AO_TS_t z = AO_TS_INITIALIZER; # endif # if defined(AO_HAVE_double_compare_and_swapXX) \ - || defined(AO_HAVE_double_loadXX) + || defined(AO_HAVE_double_loadXX) \ + || defined(AO_HAVE_double_storeXX) AO_double_t old_w; AO_double_t new_w; # endif @@ -254,6 +255,24 @@ void test_atomicXX(void) || !defined(AO_HAVE_double_load_read) MISSING(AO_double_load); # endif +# if defined(AO_HAVE_double_storeXX) + new_w.AO_val1 = 1375; + new_w.AO_val2 = 8243; + AO_double_storeXX(&old_w, new_w); + TA_assert(old_w.AO_val1 == 1375 && old_w.AO_val2 == 8243); + AO_double_storeXX(&old_w, new_w); + TA_assert(old_w.AO_val1 == 1375 && old_w.AO_val2 == 8243); + new_w.AO_val1 ^= old_w.AO_val1; + new_w.AO_val2 ^= old_w.AO_val2; + AO_double_storeXX(&old_w, new_w); + TA_assert(old_w.AO_val1 == 0 && old_w.AO_val2 == 0); +# elif !defined(AO_HAVE_double_store) \ + || !defined(AO_HAVE_double_store_full) \ + || !defined(AO_HAVE_double_store_release) \ + || !defined(AO_HAVE_double_store_release_write) \ + || !defined(AO_HAVE_double_store_write) + MISSING(AO_double_store); +# endif # if defined(AO_HAVE_compare_double_and_swap_doubleXX) TA_assert(!AO_compare_double_and_swap_doubleXX(&w, 17, 42, 12, 13)); TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0); -- 2.40.0