From bd517cf91596735d7807d43a316fcb90a4d3e711 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Wed, 11 Mar 2015 19:58:50 +0300 Subject: [PATCH] atomic_t operators update --- rpcs3/Emu/Memory/atomic.h | 116 ++++++++++++++++++++++-- rpcs3/Emu/SysCalls/Modules/cellSync.cpp | 2 +- 2 files changed, 110 insertions(+), 8 deletions(-) diff --git a/rpcs3/Emu/Memory/atomic.h b/rpcs3/Emu/Memory/atomic.h index e6f9995ec6..9641aadf95 100644 --- a/rpcs3/Emu/Memory/atomic.h +++ b/rpcs3/Emu/Memory/atomic.h @@ -197,10 +197,112 @@ public: } }; -template inline static typename std::enable_if::value, T>::type operator ++(_atomic_base>& left, int) +// Helper definitions +template using if_arithmetic_t = typename std::enable_if::value && std::is_arithmetic::value, T>::type; +template using if_arithmetic_be_t = typename std::enable_if::value && std::is_arithmetic::value, be_t>::type; +template using if_arithmetic_atomic_t = typename std::enable_if::value && std::is_arithmetic::value, _atomic_base>::type; +template using if_arithmetic_atomic_be_t = typename std::enable_if::value && std::is_arithmetic::value, _atomic_base>>::type; + +template inline static if_arithmetic_t operator ++(_atomic_base& left) { T result; + left.atomic_op([&result](T& value) + { + result = ++value; + }); + + return result; +} + +template inline static if_arithmetic_t operator --(_atomic_base& left) +{ + T result; + + left.atomic_op([&result](T& value) + { + result = --value; + }); + + return result; +} + +template inline static if_arithmetic_t operator ++(_atomic_base& left, int) +{ + T result; + + left.atomic_op([&result](T& value) + { + result = value++; + }); + + return result; +} + +template inline static if_arithmetic_t operator --(_atomic_base& left, int) +{ + T result; + + left.atomic_op([&result](T& value) + { + result = value--; + }); + + return result; +} + +template inline static if_arithmetic_t operator +=(_atomic_base& left, T2 right) +{ + T result; + + left.atomic_op([&result, right](T& value) + { + result = (value += right); + }); + + return result; +} + +template inline static if_arithmetic_t operator -=(_atomic_base& left, T2 right) +{ + T result; + + left.atomic_op([&result, right](T& value) + { + result = (value -= right); + }); + + return result; +} + +template inline static if_arithmetic_be_t operator ++(_atomic_base>& left) +{ + be_t result; + + left.atomic_op([&result](be_t& value) + { + result = ++value; + }); + + return result; +} + +template inline static if_arithmetic_be_t operator --(_atomic_base>& left) +{ + be_t result; + + left.atomic_op([&result](be_t& value) + { + result = --value; + }); + + return result; +} + +template inline static if_arithmetic_be_t operator ++(_atomic_base>& left, int) +{ + be_t result; + left.atomic_op([&result](be_t& value) { result = value++; @@ -209,9 +311,9 @@ template inline static typename std::enable_if return result; } -template inline static typename std::enable_if::value, T>::type operator --(_atomic_base>& left, int) +template inline static if_arithmetic_be_t operator --(_atomic_base>& left, int) { - T result; + be_t result; left.atomic_op([&result](be_t& value) { @@ -221,9 +323,9 @@ template inline static typename std::enable_if return result; } -template inline static typename std::enable_if::value, T>::type operator +=(_atomic_base>& left, T2 right) +template inline static if_arithmetic_be_t operator +=(_atomic_base>& left, T2 right) { - T result; + be_t result; left.atomic_op([&result, right](be_t& value) { @@ -233,9 +335,9 @@ template inline static typename std::enable_if inline static typename std::enable_if::value, T>::type operator -=(_atomic_base>& left, T2 right) +template inline static if_arithmetic_be_t operator -=(_atomic_base>& left, T2 right) { - T result; + be_t result; left.atomic_op([&result, right](be_t& value) { diff --git a/rpcs3/Emu/SysCalls/Modules/cellSync.cpp b/rpcs3/Emu/SysCalls/Modules/cellSync.cpp index 618653b7d9..56f5f43c81 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSync.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSync.cpp @@ -58,7 +58,7 @@ s32 cellSyncMutexLock(vm::ptr mutex) } // prx: increase acquire_count and remember its old value - const be_t order = be_t::make(mutex->acquire_count++); + const auto order = mutex->acquire_count++; // prx: wait until release_count is equal to old acquire_count g_sync_mutex_wm.wait_op(mutex.addr(), [mutex, order]()