From 8bf668665b107469086f16cb8ad23e47d479d2b4 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:14:37 +0200 Subject: 4.0 --- shared/loki/Threads.h | 354 +++++++++++++++++++++++++------------------------- 1 file changed, 177 insertions(+), 177 deletions(-) (limited to 'shared/loki/Threads.h') diff --git a/shared/loki/Threads.h b/shared/loki/Threads.h index 8fb5d362..690ca50f 100644 --- a/shared/loki/Threads.h +++ b/shared/loki/Threads.h @@ -92,97 +92,97 @@ #define LOKI_THREADS_MUTEX_CTOR(x) #define LOKI_THREADS_ATOMIC_FUNCTIONS \ - static IntType AtomicMultiply(volatile IntType& lval, const IntType val) \ - { \ - ::EnterCriticalSection( &atomic_mutex_ ); \ - lval *= val; \ - ::LeaveCriticalSection( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static IntType AtomicDivide(volatile IntType& lval, const IntType val) \ - { \ - ::EnterCriticalSection( &atomic_mutex_ ); \ - lval /= val; \ - ::LeaveCriticalSection( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static IntType AtomicIncrement(volatile IntType& lval) \ - { \ - ::EnterCriticalSection( &atomic_mutex_ ); \ - ++lval; \ - ::LeaveCriticalSection( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static IntType AtomicDecrement(volatile IntType& lval) \ - { \ - ::EnterCriticalSection( &atomic_mutex_ ); \ - --lval; \ - ::LeaveCriticalSection( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static void AtomicAssign(volatile IntType& lval, const IntType val) \ - { InterlockedExchange(&const_cast(lval), val); } \ - \ - static void AtomicAssign(IntType& lval, volatile const IntType& val) \ - { InterlockedExchange(&lval, val); } \ - \ - static IntType AtomicIncrement(volatile IntType& lval, const IntType compare, bool & matches ) \ - { \ - ::EnterCriticalSection( &atomic_mutex_ ); \ - ++lval; \ - matches = ( lval == compare ); \ - ::LeaveCriticalSection( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static IntType AtomicDecrement(volatile IntType& lval, const IntType compare, bool & matches ) \ - { \ - ::EnterCriticalSection( &atomic_mutex_ ); \ - --lval; \ - matches = ( lval == compare ); \ - ::LeaveCriticalSection( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static IntType AtomicAdd(volatile IntType& lval, const IntType val, const IntType compare, bool & matches ) \ - { \ - ::EnterCriticalSection( &atomic_mutex_ ); \ - lval += val; \ - matches = ( lval == compare ); \ - ::LeaveCriticalSection( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static IntType AtomicSubtract(volatile IntType& lval, const IntType val, const IntType compare, bool & matches ) \ - { \ - ::EnterCriticalSection( &atomic_mutex_ ); \ - lval -= val; \ - matches = ( lval == compare ); \ - ::LeaveCriticalSection( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static IntType AtomicMultiply(volatile IntType& lval, const IntType val, const IntType compare, bool & matches ) \ - { \ - ::EnterCriticalSection( &atomic_mutex_ ); \ - lval *= val; \ - matches = ( lval == compare ); \ - ::LeaveCriticalSection( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static IntType AtomicDivide(volatile IntType& lval, const IntType val, const IntType compare, bool & matches ) \ - { \ - ::EnterCriticalSection( &atomic_mutex_ ); \ - lval /= val; \ - matches = ( lval == compare ); \ - ::LeaveCriticalSection( &atomic_mutex_ ); \ - return lval; \ - } + static IntType AtomicMultiply(volatile IntType& lval, const IntType val) \ + { \ + ::EnterCriticalSection( &atomic_mutex_ ); \ + lval *= val; \ + ::LeaveCriticalSection( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static IntType AtomicDivide(volatile IntType& lval, const IntType val) \ + { \ + ::EnterCriticalSection( &atomic_mutex_ ); \ + lval /= val; \ + ::LeaveCriticalSection( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static IntType AtomicIncrement(volatile IntType& lval) \ + { \ + ::EnterCriticalSection( &atomic_mutex_ ); \ + ++lval; \ + ::LeaveCriticalSection( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static IntType AtomicDecrement(volatile IntType& lval) \ + { \ + ::EnterCriticalSection( &atomic_mutex_ ); \ + --lval; \ + ::LeaveCriticalSection( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static void AtomicAssign(volatile IntType& lval, const IntType val) \ + { InterlockedExchange(&const_cast(lval), val); } \ + \ + static void AtomicAssign(IntType& lval, volatile const IntType& val) \ + { InterlockedExchange(&lval, val); } \ + \ + static IntType AtomicIncrement(volatile IntType& lval, const IntType compare, bool & matches ) \ + { \ + ::EnterCriticalSection( &atomic_mutex_ ); \ + ++lval; \ + matches = ( lval == compare ); \ + ::LeaveCriticalSection( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static IntType AtomicDecrement(volatile IntType& lval, const IntType compare, bool & matches ) \ + { \ + ::EnterCriticalSection( &atomic_mutex_ ); \ + --lval; \ + matches = ( lval == compare ); \ + ::LeaveCriticalSection( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static IntType AtomicAdd(volatile IntType& lval, const IntType val, const IntType compare, bool & matches ) \ + { \ + ::EnterCriticalSection( &atomic_mutex_ ); \ + lval += val; \ + matches = ( lval == compare ); \ + ::LeaveCriticalSection( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static IntType AtomicSubtract(volatile IntType& lval, const IntType val, const IntType compare, bool & matches ) \ + { \ + ::EnterCriticalSection( &atomic_mutex_ ); \ + lval -= val; \ + matches = ( lval == compare ); \ + ::LeaveCriticalSection( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static IntType AtomicMultiply(volatile IntType& lval, const IntType val, const IntType compare, bool & matches ) \ + { \ + ::EnterCriticalSection( &atomic_mutex_ ); \ + lval *= val; \ + matches = ( lval == compare ); \ + ::LeaveCriticalSection( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static IntType AtomicDivide(volatile IntType& lval, const IntType val, const IntType compare, bool & matches ) \ + { \ + ::EnterCriticalSection( &atomic_mutex_ ); \ + lval /= val; \ + matches = ( lval == compare ); \ + ::LeaveCriticalSection( &atomic_mutex_ ); \ + return lval; \ + } #elif defined(LOKI_PTHREAD_H) @@ -206,96 +206,96 @@ #define LOKI_THREADS_LONG long #define LOKI_THREADS_ATOMIC(x) \ - pthread_mutex_lock(&atomic_mutex_); \ - x; \ - pthread_mutex_unlock(&atomic_mutex_) + pthread_mutex_lock(&atomic_mutex_); \ + x; \ + pthread_mutex_unlock(&atomic_mutex_) #define LOKI_THREADS_ATOMIC_FUNCTIONS \ private: \ - static pthread_mutex_t atomic_mutex_; \ + static pthread_mutex_t atomic_mutex_; \ public: \ - static IntType AtomicMultiply(volatile IntType& lval, const IntType val) \ - { \ - ::pthread_mutex_lock( &atomic_mutex_ ); \ - lval *= val; \ - ::pthread_mutex_unlock( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static IntType AtomicDivide(volatile IntType& lval, const IntType val) \ - { \ - ::pthread_mutex_lock( &atomic_mutex_ ); \ - lval /= val; \ - ::pthread_mutex_unlock( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static IntType AtomicIncrement(volatile IntType& lval) \ - { \ - ::pthread_mutex_lock( &atomic_mutex_ ); \ - ++lval; \ - ::pthread_mutex_unlock( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static IntType AtomicDecrement(volatile IntType& lval) \ - { \ - ::pthread_mutex_lock( &atomic_mutex_ ); \ - --lval; \ - ::pthread_mutex_unlock( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static void AtomicAssign(volatile IntType& lval, const IntType val) \ - { \ - ::pthread_mutex_lock( &atomic_mutex_ ); \ - lval = val; \ - ::pthread_mutex_unlock( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static void AtomicAssign(IntType& lval, volatile const IntType& val) \ - { \ - ::pthread_mutex_lock( &atomic_mutex_ ); \ - lval = val; \ - ::pthread_mutex_unlock( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static IntType AtomicIncrement(volatile IntType& lval, const IntType compare, bool & matches ) \ - { \ - ::pthread_mutex_lock( &atomic_mutex_ ); \ - ++lval; \ - matches = ( compare == lval ); \ - ::pthread_mutex_unlock( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static IntType AtomicDecrement(volatile IntType& lval, const IntType compare, bool & matches ) \ - { \ - ::pthread_mutex_lock( &atomic_mutex_ ); \ - --lval; \ - matches = ( compare == lval ); \ - ::pthread_mutex_unlock( &atomic_mutex_ ); \ - return lval; \ - } \ - static IntType AtomicMultiply(volatile IntType& lval, const IntType val, const IntType compare, bool & matches ) \ - { \ - ::pthread_mutex_lock( &atomic_mutex_ ); \ - lval *= val; \ - matches = ( lval == compare ); \ - ::pthread_mutex_unlock( &atomic_mutex_ ); \ - return lval; \ - } \ - \ - static IntType AtomicDivide(volatile IntType& lval, const IntType val, const IntType compare, bool & matches ) \ - { \ - ::pthread_mutex_lock( &atomic_mutex_ ); \ - lval /= val; \ - matches = ( lval == compare ); \ - ::pthread_mutex_unlock( &atomic_mutex_ ); \ - return lval; \ - } + static IntType AtomicMultiply(volatile IntType& lval, const IntType val) \ + { \ + ::pthread_mutex_lock( &atomic_mutex_ ); \ + lval *= val; \ + ::pthread_mutex_unlock( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static IntType AtomicDivide(volatile IntType& lval, const IntType val) \ + { \ + ::pthread_mutex_lock( &atomic_mutex_ ); \ + lval /= val; \ + ::pthread_mutex_unlock( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static IntType AtomicIncrement(volatile IntType& lval) \ + { \ + ::pthread_mutex_lock( &atomic_mutex_ ); \ + ++lval; \ + ::pthread_mutex_unlock( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static IntType AtomicDecrement(volatile IntType& lval) \ + { \ + ::pthread_mutex_lock( &atomic_mutex_ ); \ + --lval; \ + ::pthread_mutex_unlock( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static void AtomicAssign(volatile IntType& lval, const IntType val) \ + { \ + ::pthread_mutex_lock( &atomic_mutex_ ); \ + lval = val; \ + ::pthread_mutex_unlock( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static void AtomicAssign(IntType& lval, volatile const IntType& val) \ + { \ + ::pthread_mutex_lock( &atomic_mutex_ ); \ + lval = val; \ + ::pthread_mutex_unlock( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static IntType AtomicIncrement(volatile IntType& lval, const IntType compare, bool & matches ) \ + { \ + ::pthread_mutex_lock( &atomic_mutex_ ); \ + ++lval; \ + matches = ( compare == lval ); \ + ::pthread_mutex_unlock( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static IntType AtomicDecrement(volatile IntType& lval, const IntType compare, bool & matches ) \ + { \ + ::pthread_mutex_lock( &atomic_mutex_ ); \ + --lval; \ + matches = ( compare == lval ); \ + ::pthread_mutex_unlock( &atomic_mutex_ ); \ + return lval; \ + } \ + static IntType AtomicMultiply(volatile IntType& lval, const IntType val, const IntType compare, bool & matches ) \ + { \ + ::pthread_mutex_lock( &atomic_mutex_ ); \ + lval *= val; \ + matches = ( lval == compare ); \ + ::pthread_mutex_unlock( &atomic_mutex_ ); \ + return lval; \ + } \ + \ + static IntType AtomicDivide(volatile IntType& lval, const IntType val, const IntType compare, bool & matches ) \ + { \ + ::pthread_mutex_lock( &atomic_mutex_ ); \ + lval /= val; \ + matches = ( lval == compare ); \ + ::pthread_mutex_unlock( &atomic_mutex_ ); \ + return lval; \ + } #else // single threaded -- cgit