diff options
Diffstat (limited to 'src/corelib/thread/qatomic.h')
-rw-r--r-- | src/corelib/thread/qatomic.h | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h index 1ccaecc135..d79e168cb3 100644 --- a/src/corelib/thread/qatomic.h +++ b/src/corelib/thread/qatomic.h @@ -55,27 +55,31 @@ QT_BEGIN_NAMESPACE #endif // High-level atomic integer operations -class QAtomicInt : public QBasicAtomicInt +template <typename T> +class QAtomicInteger : public QBasicAtomicInteger<T> { public: // Non-atomic API -#ifdef Q_BASIC_ATOMIC_HAS_CONSTRUCTORS - constexpr QAtomicInt(int value = 0) Q_DECL_NOTHROW : QBasicAtomicInt(value) {} +#ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS + constexpr QAtomicInteger(T value = 0) Q_DECL_NOTHROW : QBasicAtomicInteger<T>(value) {} #else - inline QAtomicInt(int value = 0) Q_DECL_NOTHROW + inline QAtomicInteger(T value = 0) Q_DECL_NOTHROW { - _q_value = value; + this->_q_value = value; } #endif - inline QAtomicInt(const QAtomicInt &other) Q_DECL_NOTHROW + inline QAtomicInteger(const QAtomicInteger &other) Q_DECL_NOTHROW +#ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS + : QBasicAtomicInteger<T>() +#endif { - store(other.load()); + this->storeRelease(other.loadAcquire()); } - inline QAtomicInt &operator=(const QAtomicInt &other) Q_DECL_NOTHROW + inline QAtomicInteger &operator=(const QAtomicInteger &other) Q_DECL_NOTHROW { - this->store(other.load()); + this->storeRelease(other.loadAcquire()); return *this; } @@ -117,6 +121,18 @@ public: #endif }; +class QAtomicInt : public QAtomicInteger<int> +{ +public: + // Non-atomic API + // We could use QT_COMPILER_INHERITING_CONSTRUCTORS, but we need only one; + // the implicit definition for all the others is fine. +#ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS + constexpr +#endif + QAtomicInt(int value = 0) Q_DECL_NOTHROW : QAtomicInteger<int>(value) {} +}; + // High-level atomic pointer operations template <typename T> class QAtomicPointer : public QBasicAtomicPointer<T> @@ -132,12 +148,12 @@ public: #endif inline QAtomicPointer(const QAtomicPointer<T> &other) Q_DECL_NOTHROW { - this->store(other.load()); + this->storeRelease(other.loadAcquire()); } inline QAtomicPointer<T> &operator=(const QAtomicPointer<T> &other) Q_DECL_NOTHROW { - this->store(other.load()); + this->storeRelease(other.loadAcquire()); return *this; } |