commit 281705c3846ecc0142613c6b12960c96731be930 parent f6a2e3119f943016364602938f3579b9b965fdff Author: Michael Savage <mikejsavage@gmail.com> Date: Sun May 8 21:49:09 +0100 Use fetch_and_* instead of *_and_fetch Diffstat:
benchmark.cc | | | 6 | +++--- |
platform_atomic.h | | | 8 | ++++---- |
unix_atomic.h | | | 8 | ++++---- |
work_queue.cc | | | 4 | ++-- |
diff --git a/benchmark.cc b/benchmark.cc @@ -26,12 +26,12 @@ ScopedTimer::ScopedTimer( u32 idx ) { ScopedTimer::~ScopedTimer() { u64 dt = __rdtsc() - initial_clock; - atomic_add_fetch_u64( &timers[ timer_idx ].total_clocks, dt ); - atomic_add_fetch_u64( &timers[ timer_idx ].num_calls, 1 ); + atomic_fetch_add_u64( &timers[ timer_idx ].total_clocks, dt ); + atomic_fetch_add_u64( &timers[ timer_idx ].num_calls, 1 ); } u32 benchmark_new_timer( const char * fn, const char * file, int line ) { - u32 idx = atomic_add_fetch_u32( &num_timers, 1 ) - 1; + u32 idx = atomic_fetch_add_u32( &num_timers, 1 ); assert( idx < MAX_TIMERS ); Timer info; diff --git a/platform_atomic.h b/platform_atomic.h @@ -9,11 +9,11 @@ } #define ATOMIC_FUNCTION_DEF( T ) \ - inline T atomic_add_fetch( atomic_##T * atom, T x ) { \ - return atomic_add_fetch_##T( atom, x ); \ + inline T atomic_fetch_add( atomic_##T * atom, T x ) { \ + return atomic_fetch_add_##T( atom, x ); \ } \ - inline T atomic_sub_fetch( atomic_##T * atom, T x ) { \ - return atomic_sub_fetch_##T( atom, x ); \ + inline T atomic_fetch_sub( atomic_##T * atom, T x ) { \ + return atomic_fetch_sub_##T( atom, x ); \ } \ inline T atomic_swap( atomic_##T * atom, T newval ) { \ return atomic_swap_##T( atom, newval ); \ diff --git a/unix_atomic.h b/unix_atomic.h @@ -7,11 +7,11 @@ #define write_barrier() asm volatile ( "" ::: "memory" ) #define ATOMIC_DEFS( T ) \ - inline T atomic_add_fetch_##T( atomic_##T * atom, T x ) { \ - return __sync_add_and_fetch( &atom->v, x ); \ + inline T atomic_fetch_add_##T( atomic_##T * atom, T x ) { \ + return __sync_fetch_and_add( &atom->v, x ); \ } \ - inline T atomic_sub_fetch_##T( atomic_##T * atom, T x ) { \ - return __sync_sub_and_fetch( &atom->v, x ); \ + inline T atomic_fetch_sub_##T( atomic_##T * atom, T x ) { \ + return __sync_fetch_and_sub( &atom->v, x ); \ } \ inline T atomic_swap_##T( atomic_##T * atom, T x ) { \ return __sync_lock_test_and_set( &atom->v, x ); \ diff --git a/work_queue.cc b/work_queue.cc @@ -19,7 +19,7 @@ static bool workqueue_step( u32 thread_id, WorkQueue * queue ) { const Job & job = queue->jobs[ current_head ]; job.callback( job.data, &queue->arenas[ thread_id ] ); - atomic_add_fetch_u16( &queue->jobs_completed, 1 ); + atomic_fetch_add_u16( &queue->jobs_completed, 1 ); } return true; @@ -35,7 +35,7 @@ static THREAD( workqueue_worker ) { u32 thread_id = info->thread_id; write_barrier(); - atomic_add_fetch_u32( info->started_threads, 1 ); + atomic_fetch_add_u32( info->started_threads, 1 ); for( ;; ) { if( !workqueue_step( thread_id, queue ) ) {