commit 5b742eecbeb1affbe35266e3d02f4731d1654c75
parent 755afc713fcc05c4003f34e95904af250fbc1782
Author: Michael Savage <mikejsavage@gmail.com>
Date: Wed, 21 Feb 2018 19:40:14 +0200
C++11 relacy tests, now we are C++11 everywhere
Diffstat:
5 files changed, 93 insertions(+), 79 deletions(-)
diff --git a/intrinsics.h b/intrinsics.h
@@ -64,11 +64,7 @@ inline void assert_impl( const bool predicate, const char * message ) {
#define ASSERT( predicate ) assert_impl( predicate, "\x1b[1;31massertion failed at " __FILE__ " line " STRINGIFY( __LINE__ ) ": \x1b[0;1m" #predicate "\x1b[0m" )
-#if PLATFORM_CPP11 || COMPILER_MSVC
#define STATIC_ASSERT( p ) static_assert( p, #p )
-#else
-#define STATIC_ASSERT( p ) static int COUNTER_NAME( STATIC_ASSERT_ )[ int( p ) - 1 ]
-#endif
template< typename T, size_t N >
char ( &ArrayCountObj( const T ( & )[ N ] ) )[ N ];
@@ -153,10 +149,9 @@ constexpr T clamp11( T x ) {
} AtStartupInstance; \
}
-#if PLATFORM_CPP11 || COMPILER_MSVC
+#if !PLATFORM_RELACY
#define NONCOPYABLE( T ) T( const T & ) = delete; void operator=( const T & ) = delete;
#else
-// only used for relacy builds so we don't care too much
#define NONCOPYABLE( T )
#endif
diff --git a/platform.h b/platform.h
@@ -52,10 +52,6 @@
# define PLATFORM_RELACY 1
#endif
-#if __cplusplus >= 201103L
-# define PLATFORM_CPP11 1
-#endif
-
#if PLATFORM_WINDOWS
# if PLATFORM_64BIT
# define PLATFORM_NAME "windows64"
diff --git a/platform_atomic.h b/platform_atomic.h
@@ -3,12 +3,10 @@
#include "intrinsics.h"
#include "platform.h"
-#if PLATFORM_RELACY
-
-#define NONATOMIC( T ) rl::var< T >
-#define ATOMIC_ASSERT( p ) RL_ASSERT( p )
-
-#else
+/*
+ * non-relacy things
+ */
+#if !PLATFORM_RELACY
enum NonAtomicDollar { NONATOMIC_DOLLAR };
#define $ NONATOMIC_DOLLAR
@@ -25,7 +23,38 @@ struct NonAtomic {
#endif
-#if COMPILER_GCCORCLANG && !PLATFORM_RELACY
+/*
+ * GCC/clang
+ */
+#if !PLATFORM_RELACY && PLATFORM_GCCORCLANG
+
+struct atomic_s32 {
+ NONCOPYABLE( atomic_s32 );
+ atomic_s32() { store_relaxed( this, 0 ); }
+ atomic_s32( s32 x ) { store_relaxed( this, x ); }
+ s32 v;
+};
+
+struct atomic_s64 {
+ NONCOPYABLE( atomic_s64 );
+ atomic_s64() { store_relaxed( this, 0 ); }
+ atomic_s64( s64 x ) { store_relaxed( this, x ); }
+ s64 v;
+};
+
+struct atomic_u32 {
+ NONCOPYABLE( atomic_u32 );
+ atomic_u32() { store_relaxed( this, 0 ); }
+ atomic_u32( u32 x ) { store_relaxed( this, x ); }
+ u32 v;
+};
+
+struct atomic_u64 {
+ NONCOPYABLE( atomic_u64 );
+ atomic_u64() { store_relaxed( this, 0 ); }
+ atomic_u64( u64 x ) { store_relaxed( this, x ); }
+ u64 v;
+};
#define load_relaxed( atom ) __atomic_load_n( &( atom )->v, __ATOMIC_RELAXED )
#define store_relaxed( atom, x ) __atomic_store_n( &( atom )->v, ( x ), __ATOMIC_RELAXED )
@@ -58,67 +87,19 @@ struct NonAtomic {
#define exchange_seqcst( atom, x ) __atomic_exchange_n( &( atom )->v, ( x ), __ATOMIC_SEQ_CST )
#define compare_exchange_seqcst( atom, before, after ) __atomic_compare_exchange_n( &( atom )->v, ( before ), ( after ), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST )
-struct atomic_s32 {
- NONCOPYABLE( atomic_s32 );
- atomic_s32() { store_relaxed( this, 0 ); }
- atomic_s32( s32 x ) { store_relaxed( this, x ); }
- s32 v;
-};
-
-struct atomic_s64 {
- NONCOPYABLE( atomic_s64 );
- atomic_s64() { store_relaxed( this, 0 ); }
- atomic_s64( s64 x ) { store_relaxed( this, x ); }
- s64 v;
-};
-
-struct atomic_u32 {
- NONCOPYABLE( atomic_u32 );
- atomic_u32() { store_relaxed( this, 0 ); }
- atomic_u32( u32 x ) { store_relaxed( this, x ); }
- u32 v;
-};
-
-struct atomic_u64 {
- NONCOPYABLE( atomic_u64 );
- atomic_u64() { store_relaxed( this, 0 ); }
- atomic_u64( u64 x ) { store_relaxed( this, x ); }
- u64 v;
-};
-
-// TODO: maybe use these instead?
-// s32 load_relaxed( atomic_s32 * atom ) {
-// return __atomic_load_n( &atom->v, __ATOMIC_RELAXED );
-// }
-//
-// s64 load_relaxed( atomic_s64 * atom ) {
-// return __atomic_load_n( &atom->v, __ATOMIC_RELAXED );
-// }
-//
-// u32 load_relaxed( atomic_u32 * atom ) {
-// return __atomic_load_n( &atom->v, __ATOMIC_RELAXED );
-// }
-//
-// u64 load_relaxed( atomic_u64 * atom ) {
-// return __atomic_load_n( &atom->v, __ATOMIC_RELAXED );
-// }
-//
-// bool compare_exchange_relaxed( atomic_s32 * atom, s32 * before, s32 after ) {
-// return __atomic_compare_exchange_n( &atom->v, before, after, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED );
-// }
-
#endif
-#if !COMPILER_GCCORCLANG || PLATFORM_RELACY
+/*
+ * std::atomic
+ */
+#if !PLATFORM_RELACY && !PLATFORM_GCCORCLANG
-#if !PLATFORM_RELACY
#include <atomic>
-#endif
-#define atomic_s32 std::atomic< s32 >
-#define atomic_s64 std::atomic< s64 >
-#define atomic_u32 std::atomic< u32 >
-#define atomic_u64 std::atomic< u64 >
+typedef std::atomic< s32 > atomic_s32;
+typedef std::atomic< s64 > atomic_s64;
+typedef std::atomic< u32 > atomic_u32;
+typedef std::atomic< u64 > atomic_u64;
#define load_relaxed( atom ) ( atom )->load( std::memory_order_relaxed )
#define store_relaxed( atom, x ) ( atom )->store( x, std::memory_order_relaxed )
@@ -152,3 +133,49 @@ struct atomic_u64 {
#define compare_exchange_seqcst( atom, before, after ) ( atom )->compare_exchange_strong( *( before ), after, std::memory_order_seq_cst, std::memory_order_seq_cst )
#endif
+
+/*
+ * relacy
+ */
+#if PLATFORM_RELACY
+
+#define NONATOMIC( T ) rl::var< T >
+#define ATOMIC_ASSERT( p ) RL_ASSERT( p )
+
+#define atomic_s32 rl::atomic< s32 >
+#define atomic_s64 rl::atomic< s64 >
+#define atomic_u32 rl::atomic< u32 >
+#define atomic_u64 rl::atomic< u64 >
+
+#define load_relaxed( atom ) ( atom )->load( rl::memory_order_relaxed )
+#define store_relaxed( atom, x ) ( atom )->store( x, rl::memory_order_relaxed )
+#define fetch_add_relaxed( atom, x ) ( atom )->fetch_add( x, rl::memory_order_relaxed )
+#define fetch_sub_relaxed( atom, x ) ( atom )->fetch_sub( x, rl::memory_order_relaxed )
+#define exchange_relaxed( atom, x ) ( atom )->exchange( x, rl::memory_order_relaxed )
+#define compare_exchange_relaxed( atom, before, after ) ( atom )->compare_exchange_strong( *( before ), after, rl::memory_order_relaxed, rl::memory_order_relaxed )
+
+#define load_acquire( atom ) ( atom )->load( rl::memory_order_acquire )
+#define fetch_add_acquire( atom, x ) ( atom )->fetch_add( x, rl::memory_order_acquire )
+#define fetch_sub_acquire( atom, x ) ( atom )->fetch_sub( x, rl::memory_order_acquire )
+#define exchange_acquire( atom, x ) ( atom )->exchange( x, rl::memory_order_acquire )
+#define compare_exchange_acquire( atom, before, after ) ( atom )->compare_exchange_strong( *( before ), after, rl::memory_order_acquire, rl::memory_order_acquire )
+
+#define store_release( atom, x ) ( atom )->store( x, rl::memory_order_release )
+#define fetch_add_release( atom, x ) ( atom )->fetch_add( x, rl::memory_order_release )
+#define fetch_sub_release( atom, x ) ( atom )->fetch_sub( x, rl::memory_order_release )
+#define exchange_release( atom, x ) ( atom )->exchange( x, rl::memory_order_release )
+#define compare_exchange_release( atom, before, after ) ( atom )->compare_exchange_strong( *( before ), after, rl::memory_order_release, rl::memory_order_relaxed )
+
+#define fetch_add_acqrel( atom, x ) ( atom )->fetch_add( x, rl::memory_order_acq_rel )
+#define fetch_sub_acqrel( atom, x ) ( atom )->fetch_sub( x, rl::memory_order_acq_rel )
+#define exchange_acqrel( atom, x ) ( atom )->exchange( x, rl::memory_order_acq_rel )
+#define compare_exchange_acqrel( atom, before, after ) ( atom )->compare_exchange_strong( *( before ), after, rl::memory_order_acq_rel, rl::memory_order_acquire )
+
+#define load_seqcst( atom ) ( atom )->load( rl::memory_order_seq_cst )
+#define store_seqcst( atom, x ) ( atom )->store( x, rl::memory_order_seq_cst )
+#define fetch_add_seqcst( atom, x ) ( atom )->fetch_add( x, rl::memory_order_seq_cst )
+#define fetch_sub_seqcst( atom, x ) ( atom )->fetch_sub( x, rl::memory_order_seq_cst )
+#define exchange_seqcst( atom, x ) ( atom )->exchange( x, rl::memory_order_seq_cst )
+#define compare_exchange_seqcst( atom, before, after ) ( atom )->compare_exchange_strong( *( before ), after, rl::memory_order_seq_cst, rl::memory_order_seq_cst )
+
+#endif
diff --git a/tests/mpsc_relacy.cc b/tests/mpsc_relacy.cc
@@ -1,6 +1,4 @@
-#include "libs/relacy/relacy_std.hpp"
-
-#define constexpr inline // TODO: big hack
+#include "libs/relacy/relacy_cli.hpp"
#include "mpsc.h"
#define NUM_PRODUCER_THREADS 4
diff --git a/tests/spsc_relacy.cc b/tests/spsc_relacy.cc
@@ -1,6 +1,4 @@
-#include "libs/relacy/relacy_std.hpp"
-
-#define constexpr inline // TODO: big hack
+#include "libs/relacy/relacy_cli.hpp"
#include "spsc.h"
struct FixedSPSCTest : rl::test_suite< FixedSPSCTest, 2 > {