commit 7b6006ff882e548424895f3c5feb24bdcc8f8901 parent ef121a06f1b45041c867562e0689ba58c1aa8644 Author: Michael Savage <mikejsavage@gmail.com> Date: Wed Aug 31 14:22:46 -0700 Put the non-relacy atomics at the top since we care more about those Diffstat:
platform_atomic.h | | | 88 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
diff --git a/platform_atomic.h b/platform_atomic.h @@ -3,50 +3,7 @@ #include "intrinsics.h" -#ifdef RL_TEST - -#define nonatomic( T ) VAR_T( T ) -// relacy defines VAR( x ) - -#define atomic_s32 std::atomic< s32 > -#define atomic_s64 std::atomic< s64 > -#define atomic_u32 std::atomic< u32 > -#define atomic_u64 std::atomic< u64 > - -#define load_relaxed( atom ) ( atom )->load( std::memory_order_relaxed ) -#define store_relaxed( atom, x ) ( atom )->store( x, std::memory_order_relaxed ) -#define fetch_add_relaxed( atom, x ) ( atom )->fetch_add( x, std::memory_order_relaxed ) -#define exchange_relaxed( atom, x ) ( atom )->exchange( x, std::memory_order_relaxed ) -// TODO: check compare_swap_strong updates before to be consistent w/ the c11 version -#define compare_exchange_relaxed( atom, before, after ) ( atom )->compare_swap_strong( before, after, std::memory_order_relaxed, std::memory_order_relaxed ) - -#define load_acquire( atom ) ( atom )->load( std::memory_order_acquire ) -#define fetch_add_acquire( atom, x ) ( atom )->fetch_add( x, std::memory_order_acquire ) -#define exchange_acquire( atom, x ) ( atom )->exchange( x, std::memory_order_acquire ) -#define compare_exchange_acquire( atom, before, after ) ( atom )->compare_swap_strong( before, after, std::memory_order_acquire, std::memory_order_acquire ) - -#define store_release( atom, x ) ( atom )->store( x, std::memory_order_release ) -#define fetch_add_release( atom, x ) ( atom )->fetch_add( x, std::memory_order_release ) -#define exchange_release( atom, x ) ( atom )->exchange( x, std::memory_order_release ) -#define compare_exchange_release( atom, before, after ) ( atom )->compare_swap_strong( before, after, std::memory_order_release, std::memory_order_relaxed ) - -#define fetch_add_acqrel( atom, x ) ( atom )->fetch_add( x, std::memory_order_acq_rel ) -#define exchange_acqrel( atom, x ) ( atom )->exchange( x, std::memory_order_acq_rel ) -#define compare_exchange_acqrel( atom, before, after ) ( atom )->compare_swap_strong( before, after, std::memory_order_acq_rel, std::memory_order_acquire ) - -#define load_seqcst( atom ) ( atom )->load( std::memory_order_seq_cst ) -#define store_seqcst( atom, x ) ( atom )->store( x, std::memory_order_seq_cst ) -#define fetch_add_seqcst( atom, x ) ( atom )->fetch_add( x, std::memory_order_seq_cst ) -#define exchange_seqcst( atom, x ) ( atom )->exchange( x, std::memory_order_seq_cst ) -#define compare_exchange_seqcst( atom, before, after ) ( atom )->compare_swap_strong( before, after, std::memory_order_seq_cst, std::memory_order_seq_cst ) - -// relacy requires C++98 which doesn't have static_assert -// TODO: maybe this should go somewhere else? -#if __cplusplus < 201103L -#define static_assert( p ) static int CONCAT( static_assert, __COUNTER__ )[ int( p ) - 1 ] -#endif - -#else +#ifndef RL_TEST #define nonatomic( T ) T #define VAR( x ) ( x ) @@ -103,5 +60,48 @@ struct atomic_u64 { volatile u64 v; }; // return __atomic_compare_exchange_n( &atom->v, before, after, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED ); // } +#else // RL_TEST + +#define nonatomic( T ) VAR_T( T ) +// relacy defines VAR( x ) + +#define atomic_s32 std::atomic< s32 > +#define atomic_s64 std::atomic< s64 > +#define atomic_u32 std::atomic< u32 > +#define atomic_u64 std::atomic< u64 > + +#define load_relaxed( atom ) ( atom )->load( std::memory_order_relaxed ) +#define store_relaxed( atom, x ) ( atom )->store( x, std::memory_order_relaxed ) +#define fetch_add_relaxed( atom, x ) ( atom )->fetch_add( x, std::memory_order_relaxed ) +#define exchange_relaxed( atom, x ) ( atom )->exchange( x, std::memory_order_relaxed ) +// TODO: check compare_swap_strong updates before to be consistent w/ the c11 version +#define compare_exchange_relaxed( atom, before, after ) ( atom )->compare_swap_strong( before, after, std::memory_order_relaxed, std::memory_order_relaxed ) + +#define load_acquire( atom ) ( atom )->load( std::memory_order_acquire ) +#define fetch_add_acquire( atom, x ) ( atom )->fetch_add( x, std::memory_order_acquire ) +#define exchange_acquire( atom, x ) ( atom )->exchange( x, std::memory_order_acquire ) +#define compare_exchange_acquire( atom, before, after ) ( atom )->compare_swap_strong( before, after, std::memory_order_acquire, std::memory_order_acquire ) + +#define store_release( atom, x ) ( atom )->store( x, std::memory_order_release ) +#define fetch_add_release( atom, x ) ( atom )->fetch_add( x, std::memory_order_release ) +#define exchange_release( atom, x ) ( atom )->exchange( x, std::memory_order_release ) +#define compare_exchange_release( atom, before, after ) ( atom )->compare_swap_strong( before, after, std::memory_order_release, std::memory_order_relaxed ) + +#define fetch_add_acqrel( atom, x ) ( atom )->fetch_add( x, std::memory_order_acq_rel ) +#define exchange_acqrel( atom, x ) ( atom )->exchange( x, std::memory_order_acq_rel ) +#define compare_exchange_acqrel( atom, before, after ) ( atom )->compare_swap_strong( before, after, std::memory_order_acq_rel, std::memory_order_acquire ) + +#define load_seqcst( atom ) ( atom )->load( std::memory_order_seq_cst ) +#define store_seqcst( atom, x ) ( atom )->store( x, std::memory_order_seq_cst ) +#define fetch_add_seqcst( atom, x ) ( atom )->fetch_add( x, std::memory_order_seq_cst ) +#define exchange_seqcst( atom, x ) ( atom )->exchange( x, std::memory_order_seq_cst ) +#define compare_exchange_seqcst( atom, before, after ) ( atom )->compare_swap_strong( before, after, std::memory_order_seq_cst, std::memory_order_seq_cst ) + +// relacy requires C++98 which doesn't have static_assert +// TODO: maybe this should go somewhere else? +#if __cplusplus < 201103L +#define static_assert( p ) static int CONCAT( static_assert, __COUNTER__ )[ int( p ) - 1 ] +#endif + #endif // RL_TEST #endif // _PLATFORM_ATOMIC_H_