From 307c03497301015c418d4bfe462b14ed9cdf2f1b Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Mon, 30 Jan 2012 15:04:06 +0100 Subject: Port the Windows atomic implementation to use QGenericAtomicOps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First, we do not need to have the QT_INTERLOCKED_REMOVE_VOLATILE(a) macro anymore either, since the value stored in QBasicAtomicInteger is not volatile. Windows provides Interlocked*Pointer() functions in some configurations, so we provide a partial specialization of QAtomicOps for pointer types. For integer types, QAtomicOps selects an implementation based on the size of the type. At the moment, we only support 32-bit types, but it will be possible to add 64-bit later. Note that the 32-bit specialization of QAtomicOpsBySize declares the Type typedef as long, not int, since the Windows Interlocked*() API takes parameters as longs and long pointers. Since this typedef differs from the type given to QBasicAtomicInteger by the QBasicAtomicInt typedef, we need to templatise the _q_value parameter separately from the other arguments in QGenericAtomicOps. This templatisation would be necessary to port other architectures, such as PA_RISC, where we need to have an int[4] array in the atomic type while the arguments do not need this array. Change-Id: Id71fa1ae334da2023553cb402b45e6c285f1d344 Reviewed-by: Friedemann Kleint Reviewed-by: João Abecasis Reviewed-by: Thiago Macieira --- src/corelib/thread/qgenericatomic.h | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/corelib/thread/qgenericatomic.h') diff --git a/src/corelib/thread/qgenericatomic.h b/src/corelib/thread/qgenericatomic.h index a136e98adc..984ebed47b 100644 --- a/src/corelib/thread/qgenericatomic.h +++ b/src/corelib/thread/qgenericatomic.h @@ -86,8 +86,8 @@ template struct QGenericAtomicOps return _q_value; } - template static inline always_inline - void store(T &_q_value, T newValue) + template static inline always_inline + void store(T &_q_value, X newValue) { _q_value = newValue; } @@ -100,8 +100,8 @@ template struct QGenericAtomicOps return tmp; } - template static inline always_inline - void storeRelease(T &_q_value, T newValue) + template static inline always_inline + void storeRelease(T &_q_value, X newValue) { BaseClass::releaseMemoryFence(); *static_cast(&_q_value) = newValue; @@ -128,27 +128,27 @@ template struct QGenericAtomicOps // Archictectures must implement them static inline bool isTestAndSetNative(); static inline bool isTestAndSetWaitFree(); - template static inline - bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue); + template static inline + bool testAndSetRelaxed(T &_q_value, X expectedValue, X newValue); #endif - template static inline always_inline - bool testAndSetAcquire(T &_q_value, T expectedValue, T newValue) + template static inline always_inline + bool testAndSetAcquire(T &_q_value, X expectedValue, X newValue) { bool tmp = BaseClass::testAndSetRelaxed(_q_value, expectedValue, newValue); BaseClass::acquireMemoryFence(); return tmp; } - template static inline always_inline - bool testAndSetRelease(T &_q_value, T expectedValue, T newValue) + template static inline always_inline + bool testAndSetRelease(T &_q_value, X expectedValue, X newValue) { BaseClass::releaseMemoryFence(); return BaseClass::testAndSetRelaxed(_q_value, expectedValue, newValue); } - template static inline always_inline - bool testAndSetOrdered(T &_q_value, T expectedValue, T newValue) + template static inline always_inline + bool testAndSetOrdered(T &_q_value, X expectedValue, X newValue) { BaseClass::orderedMemoryFence(); return BaseClass::testAndSetRelaxed(_q_value, expectedValue, newValue); @@ -157,8 +157,8 @@ template struct QGenericAtomicOps static inline bool isFetchAndStoreNative() { return false; } static inline bool isFetchAndStoreWaitFree() { return false; } - template static inline always_inline - T fetchAndStoreRelaxed(T &_q_value, T newValue) + template static inline always_inline + T fetchAndStoreRelaxed(T &_q_value, X newValue) { // implement fetchAndStore on top of testAndSet Q_FOREVER { @@ -168,23 +168,23 @@ template struct QGenericAtomicOps } } - template static inline always_inline - T fetchAndStoreAcquire(T &_q_value, T newValue) + template static inline always_inline + T fetchAndStoreAcquire(T &_q_value, X newValue) { T tmp = BaseClass::fetchAndStoreRelaxed(_q_value, newValue); BaseClass::acquireMemoryFence(); return tmp; } - template static inline always_inline - T fetchAndStoreRelease(T &_q_value, T newValue) + template static inline always_inline + T fetchAndStoreRelease(T &_q_value, X newValue) { BaseClass::releaseMemoryFence(); return BaseClass::fetchAndStoreRelaxed(_q_value, newValue); } - template static inline always_inline - T fetchAndStoreOrdered(T &_q_value, T newValue) + template static inline always_inline + T fetchAndStoreOrdered(T &_q_value, X newValue) { BaseClass::orderedMemoryFence(); return BaseClass::fetchAndStoreRelaxed(_q_value, newValue); -- cgit v1.2.3