From 31788fc9818c9914d50c1a6a842d3dda16a26172 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 1 Jul 2012 23:22:38 +0200 Subject: QAtomic: make ctors constexpr, if possible This requires using the same chain of conditions that QBasicAtomic* uses in order to provide constructors, so we're using the newly-added macro QT_BASIC_ATOMIC_HAS_CONSTRUCTORS to check. Even though QAtomic<> is a template, we can't just use Q_DECL_CONSTEXPR since the body of the constructors needs to change, too. Change-Id: I462a80ed175040f7709c30d07d34036c6c5507d8 Reviewed-by: Thiago Macieira --- src/corelib/thread/qatomic.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h index 7b0f6bc69f..6aa8821742 100644 --- a/src/corelib/thread/qatomic.h +++ b/src/corelib/thread/qatomic.h @@ -61,10 +61,14 @@ class QAtomicInt : public QBasicAtomicInt { public: // Non-atomic API +#ifdef Q_BASIC_ATOMIC_HAS_CONSTRUCTORS + constexpr QAtomicInt(int value = 0) Q_DECL_NOTHROW : QBasicAtomicInt(value) {} +#else inline QAtomicInt(int value = 0) Q_DECL_NOTHROW { _q_value = value; } +#endif inline QAtomicInt(const QAtomicInt &other) Q_DECL_NOTHROW { @@ -115,10 +119,14 @@ template class QAtomicPointer : public QBasicAtomicPointer { public: +#ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS + constexpr QAtomicPointer(T *value = 0) Q_DECL_NOTHROW : QBasicAtomicPointer(value) {} +#else inline QAtomicPointer(T *value = 0) Q_DECL_NOTHROW { this->store(value); } +#endif inline QAtomicPointer(const QAtomicPointer &other) Q_DECL_NOTHROW { this->store(other.load()); @@ -161,6 +169,10 @@ public: # pragma GCC diagnostic pop #endif +#ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS +# undef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS +#endif + /*! This is a helper for the assignment operators of implicitly shared classes. Your assignment operator should look like this: -- cgit v1.2.3