From c7f8213bc59691f35f44a42fa5df602e742673c4 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 5 Jul 2011 23:52:29 +0200 Subject: [PATCH] Move the non-atomic and implicit functions from QBasicAtomicXXX Now, users of QBasicAtomicInt and QBasicAtomicPointer must be sure to use .load() and .store() to access the values. Change-Id: I6b48ed175618baf387dd38d821bd50e6e93c082e Reviewed-by: Bradley T. Hughes Reviewed-by: Lars Knoll --- src/corelib/thread/qatomic.h | 84 +++++++++++++++++----- src/corelib/thread/qbasicatomic.h | 65 ----------------- .../auto/sql/kernel/qsqlthread/tst_qsqlthread.cpp | 2 +- 3 files changed, 66 insertions(+), 85 deletions(-) diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h index db7024f..515e3c5 100644 --- a/src/corelib/thread/qatomic.h +++ b/src/corelib/thread/qatomic.h @@ -39,10 +39,11 @@ ** ****************************************************************************/ +#include + #ifndef QATOMIC_H #define QATOMIC_H -#include #include QT_BEGIN_HEADER @@ -51,10 +52,16 @@ QT_BEGIN_NAMESPACE QT_MODULE(Core) +#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wextra" +#endif + // High-level atomic integer operations class Q_CORE_EXPORT QAtomicInt : public QBasicAtomicInt { public: + // Non-atomic API inline QAtomicInt(int value = 0) { #ifdef QT_ARCH_PARISC @@ -62,32 +69,48 @@ public: #endif _q_value = value; } + inline QAtomicInt(const QAtomicInt &other) { #ifdef QT_ARCH_PARISC this->_q_lock[0] = this->_q_lock[1] = this->_q_lock[2] = this->_q_lock[3] = -1; #endif - _q_value = other._q_value; + store(other.load()); } inline QAtomicInt &operator=(int value) { - (void) QBasicAtomicInt::operator=(value); + this->store(value); return *this; } inline QAtomicInt &operator=(const QAtomicInt &other) { - (void) QBasicAtomicInt::operator=(other); + this->store(other.load()); return *this; } -#ifdef qdoc - bool operator==(int value) const; - bool operator!=(int value) const; - bool operator!() const; - operator int() const; + inline bool operator==(int value) const + { + return this->load() == value; + } + inline bool operator!=(int value) const + { + return this->load() != value; + } + + inline operator int() const + { + return this->load(); + } + + inline bool operator!() const + { + return !this->load(); + } + +#ifdef qdoc static bool isReferenceCountingNative(); static bool isReferenceCountingWaitFree(); @@ -130,35 +153,54 @@ public: #ifdef QT_ARCH_PARISC this->_q_lock[0] = this->_q_lock[1] = this->_q_lock[2] = this->_q_lock[3] = -1; #endif - QBasicAtomicPointer::_q_value = value; + store(value); } inline QAtomicPointer(const QAtomicPointer &other) { #ifdef QT_ARCH_PARISC this->_q_lock[0] = this->_q_lock[1] = this->_q_lock[2] = this->_q_lock[3] = -1; #endif - QBasicAtomicPointer::_q_value = other._q_value; + store(other.load()); } inline QAtomicPointer &operator=(T *value) { - (void) QBasicAtomicPointer::operator=(value); + this->store(value); return *this; } inline QAtomicPointer &operator=(const QAtomicPointer &other) { - (void) QBasicAtomicPointer::operator=(other); + this->store(other.load()); return *this; } -#ifdef qdoc - bool operator==(T *value) const; - bool operator!=(T *value) const; - bool operator!() const; - operator T *() const; - T *operator->() const; + inline bool operator==(T *value) const + { + return this->load() == value; + } + + inline bool operator!=(T *value) const + { + return this->load() != value; + } + + inline bool operator!() const + { + return !this->load(); + } + inline operator T *() const + { + return this->load(); + } + + inline T *operator->() const + { + return this->load(); + } + +#ifdef qdoc static bool isTestAndSetNative(); static bool isTestAndSetWaitFree(); @@ -185,6 +227,10 @@ public: #endif }; +#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) +# pragma GCC diagnostic pop +#endif + /*! This is a helper for the assignment operators of implicitly shared classes. Your assignment operator should look like this: diff --git a/src/corelib/thread/qbasicatomic.h b/src/corelib/thread/qbasicatomic.h index 6519d4e..d3e988d 100644 --- a/src/corelib/thread/qbasicatomic.h +++ b/src/corelib/thread/qbasicatomic.h @@ -64,36 +64,6 @@ public: volatile int _q_value; #endif - // Non-atomic API - inline bool operator==(int value) const - { - return _q_value == value; - } - - inline bool operator!=(int value) const - { - return _q_value != value; - } - - inline bool operator!() const - { - return _q_value == 0; - } - - inline operator int() const - { - return _q_value; - } - - inline QBasicAtomicInt &operator=(int value) - { -#ifdef QT_ARCH_PARISC - this->_q_lock[0] = this->_q_lock[1] = this->_q_lock[2] = this->_q_lock[3] = -1; -#endif - _q_value = value; - return *this; - } - // Atomic API, implemented in qatomic_XXX.h int load() const { return _q_value; } @@ -153,41 +123,6 @@ public: T * volatile _q_value; #endif - // Non-atomic API - inline bool operator==(T *value) const - { - return _q_value == value; - } - - inline bool operator!=(T *value) const - { - return !operator==(value); - } - - inline bool operator!() const - { - return operator==(0); - } - - inline operator T *() const - { - return _q_value; - } - - inline T *operator->() const - { - return _q_value; - } - - inline QBasicAtomicPointer &operator=(T *value) - { -#ifdef QT_ARCH_PARISC - this->_q_lock[0] = this->_q_lock[1] = this->_q_lock[2] = this->_q_lock[3] = -1; -#endif - _q_value = value; - return *this; - } - // Atomic API, implemented in qatomic_XXX.h T *load() const { return _q_value; } diff --git a/tests/auto/sql/kernel/qsqlthread/tst_qsqlthread.cpp b/tests/auto/sql/kernel/qsqlthread/tst_qsqlthread.cpp index d39b691..79ebc93 100644 --- a/tests/auto/sql/kernel/qsqlthread/tst_qsqlthread.cpp +++ b/tests/auto/sql/kernel/qsqlthread/tst_qsqlthread.cpp @@ -363,7 +363,7 @@ void tst_QSqlThread::cleanupTestCase() void tst_QSqlThread::init() { threadFinishedCount = 0; - counter = 4; + counter.store(4); } void tst_QSqlThread::cleanup() -- 2.7.4