summaryrefslogtreecommitdiffstats
path: root/src/corelib/arch/qatomic_gcc.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2013-09-16 10:59:31 -0500
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-17 03:07:09 +0200
commitcfa5c1698d357adb6c20716e60d51dc41c55ab7e (patch)
tree14fe1e42e66df80abd0b12ad2aa9ac41d51efd18 /src/corelib/arch/qatomic_gcc.h
parenta33d9351a88da98e8ea0bf63b9b2c29ecc4a745d (diff)
Fix the C++11 and GCC-atomic intrinsics when not using GCC
Both Clang and ICC complain about the use of those atomics when used with a forward-declared pointee. GCC doesn't, which makes me think it's a GCC bug. When using QBasicAtomicPointer<Foo> with these atomics, the _q_value member causes the instantiation of QAtomicOps<Foo>, which causes the instantiation of the regular member function QAtomicOps<Foo>::fetchAndAddRelaxed. The problem is that function takes a QAtomicAdditiveType<Foo>::AdditiveT as parameter, which requires sizeof(Foo). Clang 3.3 and ICC 14 correctly expand and complain. GCC 4.7-4.9 apparently don't. The fix is to apply the same trick we used for the other atomics: change all ops functions (including fetchAndAddRelaxed) to be member templates. That way, they can't be expanded until the actual use. Clang errors: qgenericatomic.h:73:33: error: invalid application of 'sizeof' to an incomplete type 'QMutexData' qatomic_gcc.h:136:48: note: in instantiation of template class 'QAtomicAdditiveType<QMutexData *>' requested here qbasicatomic.h:272:22: note: in instantiation of template class 'QAtomicOps<QMutexData *>' requested here ICC errors: qgenericatomic.h(73): error: incomplete type is not allowed detected during: instantiation of class "QAtomicAdditiveType<T *> [with T=QMutexData]" at line 111 of "qatomic_cxx11.h" instantiation of class "QAtomicOps<T> [with T=QMutexData *]" at line 272 of "qbasicatomic.h" Found-by: Tor Arne Change-Id: I9b10648cd47109a943b34a4c9926d77cd0c4fe12 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/arch/qatomic_gcc.h')
-rw-r--r--src/corelib/arch/qatomic_gcc.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/corelib/arch/qatomic_gcc.h b/src/corelib/arch/qatomic_gcc.h
index bd296053e5..61e709655d 100644
--- a/src/corelib/arch/qatomic_gcc.h
+++ b/src/corelib/arch/qatomic_gcc.h
@@ -75,16 +75,17 @@ template<> struct QAtomicIntegerTraits<char32_t> { enum { IsInteger = 1 }; };
#define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_SOMETIMES_NATIVE
#define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_SOMETIMES_NATIVE
-template <typename T> struct QAtomicOps: QGenericAtomicOps<QAtomicOps<T> >
+template <typename X> struct QAtomicOps: QGenericAtomicOps<QAtomicOps<X> >
{
// The GCC intrinsics all have fully-ordered memory semantics, so we define
// only the xxxRelaxed functions. The exception is __sync_lock_and_test,
// which has acquire semantics, so we need to define the Release and
// Ordered versions too.
- typedef T Type;
+ typedef X Type;
#ifndef __ia64__
+ template <typename T>
static T loadAcquire(const T &_q_value) Q_DECL_NOTHROW
{
T tmp = _q_value;
@@ -92,6 +93,7 @@ template <typename T> struct QAtomicOps: QGenericAtomicOps<QAtomicOps<T> >
return tmp;
}
+ template <typename T>
static void storeRelease(T &_q_value, T newValue) Q_DECL_NOTHROW
{
__sync_synchronize();
@@ -101,28 +103,32 @@ template <typename T> struct QAtomicOps: QGenericAtomicOps<QAtomicOps<T> >
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
{
return __sync_bool_compare_and_swap(&_q_value, expectedValue, newValue);
}
+ template <typename T>
static T fetchAndStoreRelaxed(T &_q_value, T newValue) Q_DECL_NOTHROW
{
return __sync_lock_test_and_set(&_q_value, newValue);
}
+ template <typename T>
static T fetchAndStoreRelease(T &_q_value, T newValue) Q_DECL_NOTHROW
{
__sync_synchronize();
return __sync_lock_test_and_set(&_q_value, newValue);
}
+ template <typename T>
static T fetchAndStoreOrdered(T &_q_value, T newValue) Q_DECL_NOTHROW
{
return fetchAndStoreRelease(_q_value, newValue);
}
- static
+ template <typename T> static
T fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW
{
return __sync_fetch_and_add(&_q_value, valueToAdd * QAtomicAdditiveType<T>::AddScale);