diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2013-12-02 18:37:05 -0800 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-30 18:05:38 +0100 |
commit | e4533e3aebeb3aa47ecfdef39d0b5bbc1186ad39 (patch) | |
tree | dba6ea0037c0e27704fa924570f5612a75a674af /src/corelib/thread/qatomic.h | |
parent | 1b3a424bcf5948aefd72e514cf40662deeabbe30 (diff) |
Introduce QAtomicInteger<T> and derive QAtomicInt from it
QAtomicInteger<T> is to QBasicAtomicInteger<T> what QAtomicInt was to
QBasicAtomicInt: just a little more syntactic sugar. The Basic classes
do not always have a constructor, since they depend on compiler
support. The constructor is always present in the non-Basic class, at
the expense of making it non-POD for C++98 code.
This commit also repurposes most of QAtomicInt's documentation for
QAtomicInteger. It adds only the Q_ATOMIC_INTnn_IS_SUPPORTED macro
that explains whether the given type is supported on this platform.
Change-Id: I58886d6fa49fea4de24015c40dae29c9fa534e00
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com>
Diffstat (limited to 'src/corelib/thread/qatomic.h')
-rw-r--r-- | src/corelib/thread/qatomic.h | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h index 78eff2a710..1bfadc4442 100644 --- a/src/corelib/thread/qatomic.h +++ b/src/corelib/thread/qatomic.h @@ -55,25 +55,29 @@ 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 QT_BASIC_ATOMIC_HAS_CONSTRUCTORS - constexpr QAtomicInt(int value = 0) Q_DECL_NOTHROW : QBasicAtomicInt(value) {} + 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->store(other.load()); } - inline QAtomicInt &operator=(const QAtomicInt &other) Q_DECL_NOTHROW + inline QAtomicInteger &operator=(const QAtomicInteger &other) Q_DECL_NOTHROW { this->store(other.load()); 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> |