commit c50543adf4285c716c31f3bb639ff27fe28dc1bf parent 1089dad5b134b3baa22bc752b7918b925ac8b3e1 Author: Michael Savage <mikejsavage@gmail.com> Date: Thu Sep 15 01:53:36 +0100 Fix atomics on Windows, disable copy operator on GCC/clang atomics Diffstat:
benchmark.cc | | | 4 | +--- |
platform_atomic.h | | | 40 | +++++++++++++++++++++++++++++++--------- |
work_queue.cc | | | 3 | ++- |
diff --git a/benchmark.cc b/benchmark.cc @@ -36,15 +36,13 @@ u32 benchmark_new_timer( const char * fn, const char * file, int line ) { u32 idx = fetch_add_relaxed( &num_timers, 1 ); assert( idx < MAX_TIMERS ); - Timer info; + Timer & info = timers[ idx ]; info.fn = fn; info.file = file; info.line = line; store_relaxed( &info.total_clocks, 0 ); store_release( &info.num_calls, 0 ); - timers[ idx ] = info; - return idx; } diff --git a/platform_atomic.h b/platform_atomic.h @@ -2,16 +2,37 @@ #define _PLATFORM_ATOMIC_H_ #include "intrinsics.h" +#include "platform.h" -#ifndef RL_TEST - +#if !PLATFORM_RELACY #define nonatomic( T ) T #define VAR( x ) ( x ) +#else +#define nonatomic( T ) VAR_T( T ) +// relacy defines VAR( x ) +#endif + +#if COMPILER_GCCORCLANG && !PLATFORM_RELACY + +struct atomic_s32 { + volatile s32 v; + atomic_s32 & operator=( atomic_s32 & rhs ) = delete; +}; -struct atomic_s32 { volatile s32 v; }; -struct atomic_s64 { volatile s64 v; }; -struct atomic_u32 { volatile u32 v; }; -struct atomic_u64 { volatile u64 v; }; +struct atomic_s64 { + volatile s64 v; + atomic_s64 & operator=( atomic_s64 & rhs ) = delete; +}; + +struct atomic_u32 { + volatile u32 v; + atomic_u32 & operator=( atomic_u32 & rhs ) = delete; +}; + +struct atomic_u64 { + volatile u64 v; + atomic_u64 & operator=( atomic_u64 & rhs ) = delete; +}; #define load_relaxed( atom ) __atomic_load_n( &( atom )->v, __ATOMIC_RELAXED ) #define store_relaxed( atom, x ) __atomic_store_n( &( atom )->v, ( x ), __ATOMIC_RELAXED ) @@ -60,10 +81,11 @@ struct atomic_u64 { volatile u64 v; }; // return __atomic_compare_exchange_n( &atom->v, before, after, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED ); // } -#else // RL_TEST +#else // COMPILER_GCCORCLANG && !PLATFORM_RELACY -#define nonatomic( T ) VAR_T( T ) -// relacy defines VAR( x ) +#if !PLATFORM_RELACY +#include <atomic> +#endif #define atomic_s32 std::atomic< s32 > #define atomic_s64 std::atomic< s64 > diff --git a/work_queue.cc b/work_queue.cc @@ -48,9 +48,10 @@ static THREAD( workqueue_worker ) { } void workqueue_init( WorkQueue * queue, MemoryArena * arena, u32 num_threads ) { - *queue = { }; semaphore_init( &queue->sem ); + store_relaxed( &queue->head, 0 ); + store_relaxed( &queue->tail, 0 ); queue->num_threads = num_threads; queue->arenas = memarena_push_many( arena, MemoryArena, num_threads + 1 );