summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-08-06 18:03:49 +0200
committerQt by Nokia <qt-info@nokia.com>2012-08-18 18:35:36 +0200
commit2b00f97ab05f144293b26d1e0d8cf4c54d222f92 (patch)
treeef1ff7fa28fdb1449f5e91830adc26c36ef34c6c
parent624911e48174094c80df7e27b28cc2b2d46f4398 (diff)
Add Q_DECL_CONSTEXPR to the isXXX functions in the new atomics.
This allows one to write code that depends on these values at compile-time. Change-Id: I7d78524ed9c70d4141360496d1d764dcbfa92e62 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/arch/qatomic_armv5.h4
-rw-r--r--src/corelib/arch/qatomic_armv6.h10
-rw-r--r--src/corelib/arch/qatomic_cxx11.h16
-rw-r--r--src/corelib/arch/qatomic_gcc.h4
-rw-r--r--src/corelib/arch/qatomic_ia64.h16
-rw-r--r--src/corelib/arch/qatomic_mips.h10
-rw-r--r--src/corelib/arch/qatomic_msvc.h28
-rw-r--r--src/corelib/arch/qatomic_unix.h12
-rw-r--r--src/corelib/arch/qatomic_x86.h20
-rw-r--r--src/corelib/thread/qatomic.h28
-rw-r--r--src/corelib/thread/qbasicatomic.h28
-rw-r--r--src/corelib/thread/qgenericatomic.h16
-rw-r--r--tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp28
13 files changed, 124 insertions, 96 deletions
diff --git a/src/corelib/arch/qatomic_armv5.h b/src/corelib/arch/qatomic_armv5.h
index c43b4de6da..5ccc1c39ff 100644
--- a/src/corelib/arch/qatomic_armv5.h
+++ b/src/corelib/arch/qatomic_armv5.h
@@ -101,8 +101,8 @@ template <int size> struct QBasicAtomicOps: QGenericAtomicOps<QBasicAtomicOps<si
template <typename T> static bool ref(T &_q_value) Q_DECL_NOTHROW;
template <typename T> static bool deref(T &_q_value) Q_DECL_NOTHROW;
- static bool isTestAndSetNative() Q_DECL_NOTHROW { return false; }
- static bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
+ static Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return false; }
+ static Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
template <typename T> static bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW;
template <typename T> static T fetchAndStoreRelaxed(T &_q_value, T newValue) Q_DECL_NOTHROW;
template <typename T> static
diff --git a/src/corelib/arch/qatomic_armv6.h b/src/corelib/arch/qatomic_armv6.h
index 95e1f28c93..1b13f84993 100644
--- a/src/corelib/arch/qatomic_armv6.h
+++ b/src/corelib/arch/qatomic_armv6.h
@@ -80,18 +80,18 @@ template <int size> struct QBasicAtomicOps: QGenericAtomicOps<QBasicAtomicOps<si
template <typename T>
static void orderedMemoryFence(const T &) Q_DECL_NOTHROW;
- static inline bool isReferenceCountingNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isReferenceCountingNative() Q_DECL_NOTHROW { return true; }
template <typename T> static bool ref(T &_q_value) Q_DECL_NOTHROW;
template <typename T> static bool deref(T &_q_value) Q_DECL_NOTHROW;
- static inline bool isTestAndSetNative() Q_DECL_NOTHROW { return true; }
- static inline bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
template <typename T> static bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW;
- static inline bool isFetchAndStoreNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return true; }
template <typename T> static T fetchAndStoreRelaxed(T &_q_value, T newValue) Q_DECL_NOTHROW;
- static inline bool isFetchAndAddNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return true; }
template <typename T> static
T fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW;
};
diff --git a/src/corelib/arch/qatomic_cxx11.h b/src/corelib/arch/qatomic_cxx11.h
index 98e8e7043e..46b94e4029 100644
--- a/src/corelib/arch/qatomic_cxx11.h
+++ b/src/corelib/arch/qatomic_cxx11.h
@@ -144,8 +144,8 @@ template <typename T> struct QAtomicOps
_q_value.store(newValue, std::memory_order_release);
}
- static inline bool isReferenceCountingNative() Q_DECL_NOTHROW { return true; }
- static inline bool isReferenceCountingWaitFree() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isReferenceCountingNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree() Q_DECL_NOTHROW { return false; }
static inline bool ref(Type &_q_value)
{
return ++_q_value != 0;
@@ -156,8 +156,8 @@ template <typename T> struct QAtomicOps
return --_q_value != 0;
}
- static inline bool isTestAndSetNative() Q_DECL_NOTHROW { return false; }
- static inline bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
static
bool testAndSetRelaxed(Type &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW
@@ -180,8 +180,8 @@ template <typename T> struct QAtomicOps
return _q_value.compare_exchange_strong(expectedValue, newValue, std::memory_order_acq_rel);
}
- static inline bool isFetchAndStoreNative() Q_DECL_NOTHROW { return false; }
- static inline bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return false; }
static T fetchAndStoreRelaxed(Type &_q_value, T newValue) Q_DECL_NOTHROW
{
@@ -203,8 +203,8 @@ template <typename T> struct QAtomicOps
return _q_value.exchange(newValue, std::memory_order_acq_rel);
}
- static inline bool isFetchAndAddNative() Q_DECL_NOTHROW { return false; }
- static inline bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return false; }
static
T fetchAndAddRelaxed(Type &_q_value, _AdditiveType valueToAdd) Q_DECL_NOTHROW
diff --git a/src/corelib/arch/qatomic_gcc.h b/src/corelib/arch/qatomic_gcc.h
index 73df3e785e..2ceb0385ec 100644
--- a/src/corelib/arch/qatomic_gcc.h
+++ b/src/corelib/arch/qatomic_gcc.h
@@ -98,8 +98,8 @@ template <typename T> struct QAtomicOps: QGenericAtomicOps<QAtomicOps<T> >
}
#endif
- static bool isTestAndSetNative() Q_DECL_NOTHROW { return false; }
- static bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
+ static Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return false; }
+ static Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
static bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW
{
return __sync_bool_compare_and_swap(&_q_value, expectedValue, newValue);
diff --git a/src/corelib/arch/qatomic_ia64.h b/src/corelib/arch/qatomic_ia64.h
index 0bf3cf78d4..c6387108e1 100644
--- a/src/corelib/arch/qatomic_ia64.h
+++ b/src/corelib/arch/qatomic_ia64.h
@@ -154,27 +154,27 @@ template <int size> struct QBasicAtomicOps: QGenericAtomicOps<QBasicAtomicOps<si
{
*static_cast<volatile T *>(&_q_value) = newValue;
}
- static inline bool isReferenceCountingNative() Q_DECL_NOTHROW { return true; }
- static inline bool isReferenceCountingWaitFree() Q_DECL_NOTHROW { return size == 4 || size == 8; }
+ static inline Q_DECL_CONSTEXPR bool isReferenceCountingNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree() Q_DECL_NOTHROW { return size == 4 || size == 8; }
template <typename T> static bool ref(T &_q_value) Q_DECL_NOTHROW;
template <typename T> static bool deref(T &_q_value) Q_DECL_NOTHROW;
- static inline bool isTestAndSetNative() Q_DECL_NOTHROW { return true; }
- static inline bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return true; }
template <typename T> static bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW;
template <typename T> static bool testAndSetAcquire(T &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW;
template <typename T> static bool testAndSetRelease(T &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW;
template <typename T> static bool testAndSetOrdered(T &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW;
- static inline bool isFetchAndStoreNative() Q_DECL_NOTHROW { return true; }
- static inline bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return true; }
template <typename T> static T fetchAndStoreRelaxed(T &_q_value, T newValue) Q_DECL_NOTHROW;
template <typename T> static T fetchAndStoreAcquire(T &_q_value, T newValue) Q_DECL_NOTHROW;
template <typename T> static T fetchAndStoreRelease(T &_q_value, T newValue) Q_DECL_NOTHROW;
template <typename T> static T fetchAndStoreOrdered(T &_q_value, T newValue) Q_DECL_NOTHROW;
- static inline bool isFetchAndAddNative() Q_DECL_NOTHROW { return true; }
- static inline bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return false; }
template <typename T> static
T fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW;
template <typename T> static
diff --git a/src/corelib/arch/qatomic_mips.h b/src/corelib/arch/qatomic_mips.h
index 9565d3749f..e662b9abc2 100644
--- a/src/corelib/arch/qatomic_mips.h
+++ b/src/corelib/arch/qatomic_mips.h
@@ -84,18 +84,18 @@ template <int size> struct QBasicAtomicOps: QGenericAtomicOps<QBasicAtomicOps<si
template <typename T>
static void orderedMemoryFence(const T &) Q_DECL_NOTHROW;
- static inline bool isReferenceCountingNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isReferenceCountingNative() Q_DECL_NOTHROW { return true; }
template <typename T> static bool ref(T &_q_value) Q_DECL_NOTHROW;
template <typename T> static bool deref(T &_q_value) Q_DECL_NOTHROW;
- static inline bool isTestAndSetNative() Q_DECL_NOTHROW { return true; }
- static inline bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
template <typename T> static bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW;
- static inline bool isFetchAndStoreNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return true; }
template <typename T> static T fetchAndStoreRelaxed(T &_q_value, T newValue) Q_DECL_NOTHROW;
- static inline bool isFetchAndAddNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return true; }
template <typename T> static
T fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW;
};
diff --git a/src/corelib/arch/qatomic_msvc.h b/src/corelib/arch/qatomic_msvc.h
index a7de122a3e..f5801a2939 100644
--- a/src/corelib/arch/qatomic_msvc.h
+++ b/src/corelib/arch/qatomic_msvc.h
@@ -276,21 +276,21 @@ struct QAtomicOpsBySize<4> : QGenericAtomicOps<QAtomicOpsBySize<4> >
// The 32-bit Interlocked*() API takes parameters as longs.
typedef long Type;
- static inline bool isReferenceCountingNative() Q_DECL_NOTHROW { return true; }
- static inline bool isReferenceCountingWaitFree() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isReferenceCountingNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree() Q_DECL_NOTHROW { return true; }
static bool ref(long &_q_value) Q_DECL_NOTHROW;
static bool deref(long &_q_value) Q_DECL_NOTHROW;
- static inline bool isTestAndSetNative() Q_DECL_NOTHROW { return true; }
- static inline bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return true; }
static bool testAndSetRelaxed(long &_q_value, long expectedValue, long newValue) Q_DECL_NOTHROW;
- static inline bool isFetchAndStoreNative() Q_DECL_NOTHROW { return true; }
- static inline bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return true; }
static long fetchAndStoreRelaxed(long &_q_value, long newValue) Q_DECL_NOTHROW;
- static inline bool isFetchAndAddNative() Q_DECL_NOTHROW { return true; }
- static inline bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return true; }
static long fetchAndAddRelaxed(long &_q_value, QAtomicAdditiveType<long>::AdditiveT valueToAdd) Q_DECL_NOTHROW;
};
@@ -329,16 +329,16 @@ struct QAtomicOps<T *> : QGenericAtomicOps<QAtomicOps<T *> >
{
typedef T *Type;
- static inline bool isTestAndSetNative() Q_DECL_NOTHROW { return true; }
- static inline bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return true; }
static bool testAndSetRelaxed(T *&_q_value, T *expectedValue, T *newValue) Q_DECL_NOTHROW;
- static inline bool isFetchAndStoreNative() Q_DECL_NOTHROW { return true; }
- static inline bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return true; }
static T *fetchAndStoreRelaxed(T *&_q_value, T *newValue) Q_DECL_NOTHROW;
- static inline bool isFetchAndAddNative() Q_DECL_NOTHROW { return true; }
- static inline bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return true; }
static T *fetchAndAddRelaxed(T *&_q_value, qptrdiff valueToAdd) Q_DECL_NOTHROW;
};
diff --git a/src/corelib/arch/qatomic_unix.h b/src/corelib/arch/qatomic_unix.h
index 3450596173..8c74e6eb7c 100644
--- a/src/corelib/arch/qatomic_unix.h
+++ b/src/corelib/arch/qatomic_unix.h
@@ -76,8 +76,8 @@ struct QAtomicOps<int> : QGenericAtomicOps<QAtomicOps<int> >
{
typedef int Type;
- static inline bool isTestAndSetNative() Q_DECL_NOTHROW { return false; }
- static inline bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
Q_CORE_EXPORT static bool testAndSetRelaxed(int &_q_value, int expectedValue, int newValue) Q_DECL_NOTHROW;
};
@@ -86,8 +86,8 @@ struct QAtomicOps<void *> : QGenericAtomicOps<QAtomicOps<void *> >
{
typedef void *Type;
- static inline bool isTestAndSetNative() Q_DECL_NOTHROW { return false; }
- static inline bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
Q_CORE_EXPORT static bool testAndSetRelaxed(void *&_q_value, void *expectedValue, void *newValue) Q_DECL_NOTHROW;
};
@@ -99,8 +99,8 @@ struct QAtomicOps<T *> : QGenericAtomicOps<QAtomicOps<T *> >
// helper to strip cv qualifiers
static inline void *nocv(const T *p) { return const_cast<void *>(static_cast<const volatile void *>(p)); }
- static inline bool isTestAndSetNative() Q_DECL_NOTHROW { return false; }
- static inline bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
static inline bool testAndSetRelaxed(T *&_q_value, T *expectedValue, T *newValue) Q_DECL_NOTHROW
{
// forward to the void* specialization
diff --git a/src/corelib/arch/qatomic_x86.h b/src/corelib/arch/qatomic_x86.h
index 196073a590..094bf1ecb7 100644
--- a/src/corelib/arch/qatomic_x86.h
+++ b/src/corelib/arch/qatomic_x86.h
@@ -97,21 +97,21 @@ template<> struct QAtomicIntegerTraits<unsigned int> { enum { IsInteger = 1 }; }
template <int size> struct QBasicAtomicOps: QGenericAtomicOps<QBasicAtomicOps<size> >
{
- static inline bool isReferenceCountingNative() Q_DECL_NOTHROW { return true; }
- static inline bool isReferenceCountingWaitFree() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isReferenceCountingNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree() Q_DECL_NOTHROW { return true; }
template <typename T> static bool ref(T &_q_value) Q_DECL_NOTHROW;
template <typename T> static bool deref(T &_q_value) Q_DECL_NOTHROW;
- static inline bool isTestAndSetNative() Q_DECL_NOTHROW { return true; }
- static inline bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return true; }
template <typename T> static bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW;
- static inline bool isFetchAndStoreNative() Q_DECL_NOTHROW { return true; }
- static inline bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return true; }
template <typename T> static T fetchAndStoreRelaxed(T &_q_value, T newValue) Q_DECL_NOTHROW;
- static inline bool isFetchAndAddNative() Q_DECL_NOTHROW { return true; }
- static inline bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return true; }
template <typename T> static
T fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW;
};
@@ -381,8 +381,8 @@ bool QBasicAtomicOps<8>::deref(T &_q_value) Q_DECL_NOTHROW
// i386 architecture, emulate 64-bit support via cmpxchg8b
template <> struct QBasicAtomicOps<8>: QGenericAtomicOps<QBasicAtomicOps<8> >
{
- static inline bool isTestAndSetNative() Q_DECL_NOTHROW { return true; }
- static inline bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return true; }
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return true; }
template <typename T> static inline
bool testAndSetRelaxed(T &_q_value, T expectedValue, T newValue) Q_DECL_NOTHROW
{
diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h
index 2eb0a03cc6..7b0f6bc69f 100644
--- a/src/corelib/thread/qatomic.h
+++ b/src/corelib/thread/qatomic.h
@@ -78,30 +78,30 @@ public:
}
#ifdef qdoc
- static bool isReferenceCountingNative();
- static bool isReferenceCountingWaitFree();
+ static Q_DECL_CONSTEXPR bool isReferenceCountingNative();
+ static Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree();
bool ref();
bool deref();
- static bool isTestAndSetNative();
- static bool isTestAndSetWaitFree();
+ static Q_DECL_CONSTEXPR bool isTestAndSetNative();
+ static Q_DECL_CONSTEXPR bool isTestAndSetWaitFree();
bool testAndSetRelaxed(int expectedValue, int newValue);
bool testAndSetAcquire(int expectedValue, int newValue);
bool testAndSetRelease(int expectedValue, int newValue);
bool testAndSetOrdered(int expectedValue, int newValue);
- static bool isFetchAndStoreNative();
- static bool isFetchAndStoreWaitFree();
+ static Q_DECL_CONSTEXPR bool isFetchAndStoreNative();
+ static Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree();
int fetchAndStoreRelaxed(int newValue);
int fetchAndStoreAcquire(int newValue);
int fetchAndStoreRelease(int newValue);
int fetchAndStoreOrdered(int newValue);
- static bool isFetchAndAddNative();
- static bool isFetchAndAddWaitFree();
+ static Q_DECL_CONSTEXPR bool isFetchAndAddNative();
+ static Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree();
int fetchAndAddRelaxed(int valueToAdd);
int fetchAndAddAcquire(int valueToAdd);
@@ -131,24 +131,24 @@ public:
}
#ifdef qdoc
- static bool isTestAndSetNative();
- static bool isTestAndSetWaitFree();
+ static Q_DECL_CONSTEXPR bool isTestAndSetNative();
+ static Q_DECL_CONSTEXPR bool isTestAndSetWaitFree();
bool testAndSetRelaxed(T *expectedValue, T *newValue);
bool testAndSetAcquire(T *expectedValue, T *newValue);
bool testAndSetRelease(T *expectedValue, T *newValue);
bool testAndSetOrdered(T *expectedValue, T *newValue);
- static bool isFetchAndStoreNative();
- static bool isFetchAndStoreWaitFree();
+ static Q_DECL_CONSTEXPR bool isFetchAndStoreNative();
+ static Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree();
T *fetchAndStoreRelaxed(T *newValue);
T *fetchAndStoreAcquire(T *newValue);
T *fetchAndStoreRelease(T *newValue);
T *fetchAndStoreOrdered(T *newValue);
- static bool isFetchAndAddNative();
- static bool isFetchAndAddWaitFree();
+ static Q_DECL_CONSTEXPR bool isFetchAndAddNative();
+ static Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree();
T *fetchAndAddRelaxed(qptrdiff valueToAdd);
T *fetchAndAddAcquire(qptrdiff valueToAdd);
diff --git a/src/corelib/thread/qbasicatomic.h b/src/corelib/thread/qbasicatomic.h
index 3c8615decb..8aec250f90 100644
--- a/src/corelib/thread/qbasicatomic.h
+++ b/src/corelib/thread/qbasicatomic.h
@@ -137,14 +137,14 @@ public:
T loadAcquire() const Q_DECL_NOTHROW { return Ops::loadAcquire(_q_value); }
void storeRelease(T newValue) Q_DECL_NOTHROW { Ops::storeRelease(_q_value, newValue); }
- static bool isReferenceCountingNative() Q_DECL_NOTHROW { return Ops::isReferenceCountingNative(); }
- static bool isReferenceCountingWaitFree() Q_DECL_NOTHROW { return Ops::isReferenceCountingWaitFree(); }
+ static Q_DECL_CONSTEXPR bool isReferenceCountingNative() Q_DECL_NOTHROW { return Ops::isReferenceCountingNative(); }
+ static Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree() Q_DECL_NOTHROW { return Ops::isReferenceCountingWaitFree(); }
bool ref() Q_DECL_NOTHROW { return Ops::ref(_q_value); }
bool deref() Q_DECL_NOTHROW { return Ops::deref(_q_value); }
- static bool isTestAndSetNative() Q_DECL_NOTHROW { return Ops::isTestAndSetNative(); }
- static bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return Ops::isTestAndSetWaitFree(); }
+ static Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return Ops::isTestAndSetNative(); }
+ static Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return Ops::isTestAndSetWaitFree(); }
bool testAndSetRelaxed(T expectedValue, T newValue) Q_DECL_NOTHROW
{ return Ops::testAndSetRelaxed(_q_value, expectedValue, newValue); }
@@ -155,8 +155,8 @@ public:
bool testAndSetOrdered(T expectedValue, T newValue) Q_DECL_NOTHROW
{ return Ops::testAndSetOrdered(_q_value, expectedValue, newValue); }
- static bool isFetchAndStoreNative() Q_DECL_NOTHROW { return Ops::isFetchAndStoreNative(); }
- static bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return Ops::isFetchAndStoreWaitFree(); }
+ static Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return Ops::isFetchAndStoreNative(); }
+ static Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return Ops::isFetchAndStoreWaitFree(); }
T fetchAndStoreRelaxed(T newValue) Q_DECL_NOTHROW
{ return Ops::fetchAndStoreRelaxed(_q_value, newValue); }
@@ -167,8 +167,8 @@ public:
T fetchAndStoreOrdered(T newValue) Q_DECL_NOTHROW
{ return Ops::fetchAndStoreOrdered(_q_value, newValue); }
- static bool isFetchAndAddNative() Q_DECL_NOTHROW { return Ops::isFetchAndAddNative(); }
- static bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return Ops::isFetchAndAddWaitFree(); }
+ static Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return Ops::isFetchAndAddNative(); }
+ static Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return Ops::isFetchAndAddWaitFree(); }
T fetchAndAddRelaxed(T valueToAdd) Q_DECL_NOTHROW
{ return Ops::fetchAndAddRelaxed(_q_value, valueToAdd); }
@@ -207,8 +207,8 @@ public:
Type loadAcquire() const Q_DECL_NOTHROW { return Ops::loadAcquire(_q_value); }
void storeRelease(Type newValue) Q_DECL_NOTHROW { Ops::storeRelease(_q_value, newValue); }
- static bool isTestAndSetNative() Q_DECL_NOTHROW { return Ops::isTestAndSetNative(); }
- static bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return Ops::isTestAndSetWaitFree(); }
+ static Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return Ops::isTestAndSetNative(); }
+ static Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return Ops::isTestAndSetWaitFree(); }
bool testAndSetRelaxed(Type expectedValue, Type newValue) Q_DECL_NOTHROW
{ return Ops::testAndSetRelaxed(_q_value, expectedValue, newValue); }
@@ -219,8 +219,8 @@ public:
bool testAndSetOrdered(Type expectedValue, Type newValue) Q_DECL_NOTHROW
{ return Ops::testAndSetOrdered(_q_value, expectedValue, newValue); }
- static bool isFetchAndStoreNative() Q_DECL_NOTHROW { return Ops::isFetchAndStoreNative(); }
- static bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return Ops::isFetchAndStoreWaitFree(); }
+ static Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return Ops::isFetchAndStoreNative(); }
+ static Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return Ops::isFetchAndStoreWaitFree(); }
Type fetchAndStoreRelaxed(Type newValue) Q_DECL_NOTHROW
{ return Ops::fetchAndStoreRelaxed(_q_value, newValue); }
@@ -231,8 +231,8 @@ public:
Type fetchAndStoreOrdered(Type newValue) Q_DECL_NOTHROW
{ return Ops::fetchAndStoreOrdered(_q_value, newValue); }
- static bool isFetchAndAddNative() Q_DECL_NOTHROW { return Ops::isFetchAndAddNative(); }
- static bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return Ops::isFetchAndAddWaitFree(); }
+ static Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return Ops::isFetchAndAddNative(); }
+ static Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return Ops::isFetchAndAddWaitFree(); }
Type fetchAndAddRelaxed(qptrdiff valueToAdd) Q_DECL_NOTHROW
{ return Ops::fetchAndAddRelaxed(_q_value, valueToAdd); }
diff --git a/src/corelib/thread/qgenericatomic.h b/src/corelib/thread/qgenericatomic.h
index 46f373b797..059e0f6e8f 100644
--- a/src/corelib/thread/qgenericatomic.h
+++ b/src/corelib/thread/qgenericatomic.h
@@ -119,9 +119,9 @@ template <typename BaseClass> struct QGenericAtomicOps
*static_cast<volatile T *>(&_q_value) = newValue;
}
- static inline bool isReferenceCountingNative() Q_DECL_NOTHROW
+ static inline Q_DECL_CONSTEXPR bool isReferenceCountingNative() Q_DECL_NOTHROW
{ return BaseClass::isFetchAndAddNative(); }
- static inline bool isReferenceCountingWaitFree() Q_DECL_NOTHROW
+ static inline Q_DECL_CONSTEXPR bool isReferenceCountingWaitFree() Q_DECL_NOTHROW
{ return BaseClass::isFetchAndAddWaitFree(); }
template <typename T> static inline always_inline
bool ref(T &_q_value) Q_DECL_NOTHROW
@@ -138,8 +138,8 @@ template <typename BaseClass> struct QGenericAtomicOps
#if 0
// These functions have no default implementation
// Archictectures must implement them
- static inline bool isTestAndSetNative() Q_DECL_NOTHROW;
- static inline bool isTestAndSetWaitFree() Q_DECL_NOTHROW;
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW;
+ static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW;
template <typename T, typename X> static inline
bool testAndSetRelaxed(T &_q_value, X expectedValue, X newValue) Q_DECL_NOTHROW;
#endif
@@ -166,8 +166,8 @@ template <typename BaseClass> struct QGenericAtomicOps
return BaseClass::testAndSetRelaxed(_q_value, expectedValue, newValue);
}
- static inline bool isFetchAndStoreNative() Q_DECL_NOTHROW { return false; }
- static inline bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndStoreNative() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndStoreWaitFree() Q_DECL_NOTHROW { return false; }
template <typename T, typename X> static inline always_inline
T fetchAndStoreRelaxed(T &_q_value, X newValue) Q_DECL_NOTHROW
@@ -202,8 +202,8 @@ template <typename BaseClass> struct QGenericAtomicOps
return BaseClass::fetchAndStoreRelaxed(_q_value, newValue);
}
- static inline bool isFetchAndAddNative() Q_DECL_NOTHROW { return false; }
- static inline bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndAddNative() Q_DECL_NOTHROW { return false; }
+ static inline Q_DECL_CONSTEXPR bool isFetchAndAddWaitFree() Q_DECL_NOTHROW { return false; }
template <typename T> static inline always_inline
T fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
{
diff --git a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp
index c2dc8a4cc6..1283083f0e 100644
--- a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp
+++ b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp
@@ -161,6 +161,25 @@ static void warningFreeHelperTemplate()
assemblyMarker<64>(&i);
}
+template <bool> inline void booleanHelper()
+{ }
+
+template <typename Atomic>
+static void constexprFunctionsHelperTemplate()
+{
+#ifdef Q_COMPILER_CONSTEXPR
+ // this is a compile-time test only
+ booleanHelper<Atomic::isReferenceCountingNative()>();
+ booleanHelper<Atomic::isReferenceCountingWaitFree()>();
+ booleanHelper<Atomic::isTestAndSetNative()>();
+ booleanHelper<Atomic::isTestAndSetWaitFree()>();
+ booleanHelper<Atomic::isFetchAndStoreNative()>();
+ booleanHelper<Atomic::isFetchAndStoreWaitFree()>();
+ booleanHelper<Atomic::isFetchAndAddNative()>();
+ booleanHelper<Atomic::isFetchAndAddWaitFree()>();
+#endif
+}
+
void tst_QAtomicInt::warningFreeHelper()
{
qFatal("This code is bogus, and shouldn't be run. We're looking for compiler warnings only.");
@@ -169,23 +188,32 @@ void tst_QAtomicInt::warningFreeHelper()
#ifdef Q_ATOMIC_INT32_IS_SUPPORTED
warningFreeHelperTemplate<int, QBasicAtomicInteger<int> >();
warningFreeHelperTemplate<unsigned int, QBasicAtomicInteger<unsigned int> >();
+ constexprFunctionsHelperTemplate<QBasicAtomicInteger<int> >();
+ constexprFunctionsHelperTemplate<QBasicAtomicInteger<unsigned int> >();
#endif
#ifdef Q_ATOMIC_INT16_IS_SUPPORTED
warningFreeHelperTemplate<qint16, QBasicAtomicInteger<qint16> >();
warningFreeHelperTemplate<quint16, QBasicAtomicInteger<quint16> >();
+ constexprFunctionsHelperTemplate<QBasicAtomicInteger<qint16> >();
+ constexprFunctionsHelperTemplate<QBasicAtomicInteger<quint16> >();
#endif
#ifdef Q_ATOMIC_INT8_IS_SUPPORTED
warningFreeHelperTemplate<char, QBasicAtomicInteger<char> >();
warningFreeHelperTemplate<signed char, QBasicAtomicInteger<signed char> >();
warningFreeHelperTemplate<unsigned char, QBasicAtomicInteger<unsigned char> >();
+ constexprFunctionsHelperTemplate<QBasicAtomicInteger<char> >();
+ constexprFunctionsHelperTemplate<QBasicAtomicInteger<signed char> >();
+ constexprFunctionsHelperTemplate<QBasicAtomicInteger<unsigned char> >();
#endif
#ifdef Q_ATOMIC_INT64_IS_SUPPORTED
#if !defined(__i386__) || (defined(Q_CC_GNU) && defined(__OPTIMIZE__))
warningFreeHelperTemplate<qlonglong, QBasicAtomicInteger<qlonglong> >();
warningFreeHelperTemplate<qulonglong, QBasicAtomicInteger<qulonglong> >();
+ constexprFunctionsHelperTemplate<QBasicAtomicInteger<qlonglong> >();
+ constexprFunctionsHelperTemplate<QBasicAtomicInteger<qulonglong> >();
#endif
#endif
}