diff options
Diffstat (limited to 'src/corelib/arch/qatomic_cxx11.h')
-rw-r--r-- | src/corelib/arch/qatomic_cxx11.h | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/src/corelib/arch/qatomic_cxx11.h b/src/corelib/arch/qatomic_cxx11.h index 55e71e1e88..b07e470484 100644 --- a/src/corelib/arch/qatomic_cxx11.h +++ b/src/corelib/arch/qatomic_cxx11.h @@ -70,22 +70,9 @@ QT_END_NAMESPACE #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_SOMETIMES_NATIVE #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_SOMETIMES_NATIVE -template<> struct QAtomicIntegerTraits<int> { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits<unsigned int> { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits<char> { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits<signed char> { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits<unsigned char> { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits<short> { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits<unsigned short> { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits<long> { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits<unsigned long> { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits<long long> { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits<unsigned long long> { enum { IsInteger = 1 }; }; - -# ifdef Q_COMPILER_UNICODE_STRINGS -template<> struct QAtomicIntegerTraits<char16_t> { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits<char32_t> { enum { IsInteger = 1 }; }; -# endif +template<> struct QAtomicOpsSupport<1> { enum { IsSupported = 1 }; }; +template<> struct QAtomicOpsSupport<2> { enum { IsSupported = 1 }; }; +template<> struct QAtomicOpsSupport<8> { enum { IsSupported = 1 }; }; #define Q_ATOMIC_INT8_IS_SUPPORTED #define Q_ATOMIC_INT8_REFERENCE_COUNTING_IS_ALWAYS_NATIVE @@ -162,28 +149,40 @@ template <typename X> struct QAtomicOps static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return false; } static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; } - template <typename T> static - bool testAndSetRelaxed(Type &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW + template <typename T> + static bool testAndSetRelaxed(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = 0) Q_DECL_NOTHROW { - return _q_value.compare_exchange_strong(expectedValue, newValue, std::memory_order_relaxed); + bool tmp = _q_value.compare_exchange_strong(expectedValue, newValue, std::memory_order_relaxed); + if (currentValue) + *currentValue = expectedValue; + return tmp; } template <typename T> - static bool testAndSetAcquire(Type &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW + static bool testAndSetAcquire(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = 0) Q_DECL_NOTHROW { - return _q_value.compare_exchange_strong(expectedValue, newValue, std::memory_order_acquire); + bool tmp = _q_value.compare_exchange_strong(expectedValue, newValue, std::memory_order_acquire); + if (currentValue) + *currentValue = expectedValue; + return tmp; } template <typename T> - static bool testAndSetRelease(Type &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW + static bool testAndSetRelease(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = 0) Q_DECL_NOTHROW { - return _q_value.compare_exchange_strong(expectedValue, newValue, std::memory_order_release); + bool tmp = _q_value.compare_exchange_strong(expectedValue, newValue, std::memory_order_release); + if (currentValue) + *currentValue = expectedValue; + return tmp; } template <typename T> - static bool testAndSetOrdered(Type &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW + static bool testAndSetOrdered(std::atomic<T> &_q_value, T expectedValue, T newValue, T *currentValue = 0) Q_DECL_NOTHROW { - return _q_value.compare_exchange_strong(expectedValue, newValue, std::memory_order_acq_rel); + bool tmp = _q_value.compare_exchange_strong(expectedValue, newValue, std::memory_order_acq_rel); + if (currentValue) + *currentValue = expectedValue; + return tmp; } static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return false; } |