From aba30f02348c60ea785c374d12e1f3998dc4cb14 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 2 Dec 2013 19:50:29 -0800 Subject: Replace the type-based QAtomicIntegerTraits with a size-based one This simplifies the code a lot and avoids silly mistakes where a specific integer type is missing (such as char16_t). Change-Id: Id91dfd1919e783e0a9af7bfa093ca560a01b22d1 Reviewed-by: Lars Knoll --- src/corelib/arch/qatomic_armv6.h | 14 +++----------- src/corelib/arch/qatomic_cxx11.h | 14 +++----------- src/corelib/arch/qatomic_gcc.h | 3 +-- src/corelib/arch/qatomic_ia64.h | 14 +++----------- src/corelib/arch/qatomic_mips.h | 9 +-------- src/corelib/arch/qatomic_msvc.h | 6 ++---- src/corelib/arch/qatomic_unix.h | 3 --- src/corelib/arch/qatomic_x86.h | 15 +++------------ src/corelib/thread/qbasicatomic.h | 3 ++- src/corelib/thread/qgenericatomic.h | 16 ++-------------- 10 files changed, 20 insertions(+), 77 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/arch/qatomic_armv6.h b/src/corelib/arch/qatomic_armv6.h index b8401d185d..37df64141c 100644 --- a/src/corelib/arch/qatomic_armv6.h +++ b/src/corelib/arch/qatomic_armv6.h @@ -210,17 +210,9 @@ T QBasicAtomicOps<4>::fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveTy || defined(__ARM_ARCH_6K__) // LDREXB, LDREXH and LDREXD are available on ARMv6K or higher -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; - -# ifdef Q_COMPILER_UNICODE_STRINGS -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -# endif +template<> struct QAtomicOpsSupport<1> { enum { IsSupported = 1 }; }; +template<> struct QAtomicOpsSupport<2> { enum { IsSupported = 1 }; }; +template<> struct QAtomicOpsSupport<8> { enum { IsSupported = 1 }; }; #define Q_ATOMIC_INT8_IS_SUPPORTED #define Q_ATOMIC_INT8_REFERENCE_COUNTING_IS_ALWAYS_NATIVE diff --git a/src/corelib/arch/qatomic_cxx11.h b/src/corelib/arch/qatomic_cxx11.h index 87eb7b3fab..85575da20e 100644 --- a/src/corelib/arch/qatomic_cxx11.h +++ b/src/corelib/arch/qatomic_cxx11.h @@ -70,17 +70,9 @@ QT_END_NAMESPACE #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_SOMETIMES_NATIVE #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_SOMETIMES_NATIVE -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; - -# ifdef Q_COMPILER_UNICODE_STRINGS -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -# endif +template<> struct QAtomicOpsSupport<1> { enum { IsSupported = 1 }; }; +template<> struct QAtomicOpsSupport<2> { enum { IsSupported = 1 }; }; +template<> struct QAtomicOpsSupport<8> { enum { IsSupported = 1 }; }; #define Q_ATOMIC_INT8_IS_SUPPORTED #define Q_ATOMIC_INT8_REFERENCE_COUNTING_IS_ALWAYS_NATIVE diff --git a/src/corelib/arch/qatomic_gcc.h b/src/corelib/arch/qatomic_gcc.h index 7a8672510f..052453c082 100644 --- a/src/corelib/arch/qatomic_gcc.h +++ b/src/corelib/arch/qatomic_gcc.h @@ -75,8 +75,7 @@ QT_END_NAMESPACE # define Q_ATOMIC_INT64_TEST_AND_SET_IS_SOMETIMES_NATIVE # define Q_ATOMIC_INT64_FETCH_AND_STORE_IS_SOMETIMES_NATIVE # define Q_ATOMIC_INT64_FETCH_AND_ADD_IS_SOMETIMES_NATIVE -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; +template<> struct QAtomicOpsSupport<8> { enum { IsSupported = 1 }; }; #endif template struct QAtomicOps: QGenericAtomicOps > diff --git a/src/corelib/arch/qatomic_ia64.h b/src/corelib/arch/qatomic_ia64.h index 2abba95c6c..0075f32a42 100644 --- a/src/corelib/arch/qatomic_ia64.h +++ b/src/corelib/arch/qatomic_ia64.h @@ -123,17 +123,9 @@ QT_END_NAMESPACE #define Q_ATOMIC_INT64_FETCH_AND_ADD_IS_ALWAYS_NATIVE -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; - -# ifdef Q_COMPILER_UNICODE_STRINGS -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -# endif +template<> struct QAtomicOpsSupport<1> { enum { IsSupported = 1 }; }; +template<> struct QAtomicOpsSupport<2> { enum { IsSupported = 1 }; }; +template<> struct QAtomicOpsSupport<8> { enum { IsSupported = 1 }; }; template struct QBasicAtomicOps: QGenericAtomicOps > { diff --git a/src/corelib/arch/qatomic_mips.h b/src/corelib/arch/qatomic_mips.h index e9a4e31c75..9c744b885d 100644 --- a/src/corelib/arch/qatomic_mips.h +++ b/src/corelib/arch/qatomic_mips.h @@ -232,14 +232,7 @@ T QBasicAtomicOps<4>::fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveTy #define Q_ATOMIC_INT64_FETCH_AND_STORE_IS_ALWAYS_NATIVE #define Q_ATOMIC_INT64_FETCH_AND_ADD_IS_ALWAYS_NATIVE -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; - -#ifdef Q_COMPILER_UNICODE_STRINGS -template<> struct QAtomicIntegerTraits -{ enum { IsInteger = sizeof(char16_t) == sizeof(int) ? 1 : -1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -#endif +template<> struct QAtomicOpsSupport<8> { enum { IsSupported = 1 }; }; template<> template inline bool QBasicAtomicOps<8>::ref(T &_q_value) Q_DECL_NOTHROW diff --git a/src/corelib/arch/qatomic_msvc.h b/src/corelib/arch/qatomic_msvc.h index 7ba70259e9..1cbb1442ed 100644 --- a/src/corelib/arch/qatomic_msvc.h +++ b/src/corelib/arch/qatomic_msvc.h @@ -275,8 +275,7 @@ QT_END_NAMESPACE # define Q_ATOMIC_INT16_FETCH_AND_ADD_IS_ALWAYS_NATIVE # define Q_ATOMIC_INT16_FETCH_AND_ADD_IS_WAIT_FREE -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; +template<> struct QAtomicOpsSupport<2> { enum { IsSupported = 1 }; }; #endif #ifdef Q_ATOMIC_INT64_IS_SUPPORTED @@ -292,8 +291,7 @@ template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; # define Q_ATOMIC_INT64_FETCH_AND_ADD_IS_ALWAYS_NATIVE # define Q_ATOMIC_INT64_FETCH_AND_ADD_IS_WAIT_FREE -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; +template<> struct QAtomicOpsSupport<8> { enum { IsSupported = 1 }; }; #endif //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/corelib/arch/qatomic_unix.h b/src/corelib/arch/qatomic_unix.h index 493927fac0..6ed9864073 100644 --- a/src/corelib/arch/qatomic_unix.h +++ b/src/corelib/arch/qatomic_unix.h @@ -74,9 +74,6 @@ QT_END_NAMESPACE #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_NOT_NATIVE #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_NOT_NATIVE -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; - // No definition, needs specialization template struct QAtomicOps; diff --git a/src/corelib/arch/qatomic_x86.h b/src/corelib/arch/qatomic_x86.h index 6ed283396d..2013d8f991 100644 --- a/src/corelib/arch/qatomic_x86.h +++ b/src/corelib/arch/qatomic_x86.h @@ -117,18 +117,9 @@ template struct QAtomicOps : QBasicAtomicOps #if defined(Q_CC_GNU) -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; - -# ifdef Q_COMPILER_UNICODE_STRINGS -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -# endif - +template<> struct QAtomicOpsSupport<1> { enum { IsSupported = 1 }; }; +template<> struct QAtomicOpsSupport<2> { enum { IsSupported = 1 }; }; +template<> struct QAtomicOpsSupport<8> { enum { IsSupported = 1 }; }; /* * Guide for the inline assembly below: diff --git a/src/corelib/thread/qbasicatomic.h b/src/corelib/thread/qbasicatomic.h index 9fa12ba811..f75a24ae10 100644 --- a/src/corelib/thread/qbasicatomic.h +++ b/src/corelib/thread/qbasicatomic.h @@ -114,7 +114,8 @@ class QBasicAtomicInteger public: typedef QAtomicOps Ops; // static check that this is a valid integer - Q_STATIC_ASSERT_X(QAtomicIntegerTraits::IsInteger, "Template parameter is not a supported integer on this platform"); + Q_STATIC_ASSERT_X(QTypeInfo::isIntegral, "template parameter is not an integral type"); + Q_STATIC_ASSERT_X(QAtomicOpsSupport::IsSupported, "template parameter is an integral of a size not supported on this platform"); typename Ops::Type _q_value; diff --git a/src/corelib/thread/qgenericatomic.h b/src/corelib/thread/qgenericatomic.h index bbdc57ca50..eacde411b9 100644 --- a/src/corelib/thread/qgenericatomic.h +++ b/src/corelib/thread/qgenericatomic.h @@ -60,20 +60,8 @@ QT_END_NAMESPACE #define always_inline #endif -template struct QAtomicIntegerTraits { enum { IsInteger = 0 }; }; - -// these integers are always supported, on all platforms -// - int, unsigned int and char32_t are 32-bit wide -// - long and unsigned long might be 64-bit wide on 64-bit platforms, -// but 64-bit integer support is required anyway -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; -#ifdef Q_COMPILER_UNICODE_STRINGS -template<> struct QAtomicIntegerTraits -{ enum { IsInteger = sizeof(char32_t) == sizeof(int) ? 1 : -1 }; }; -#endif +template struct QAtomicOpsSupport { enum { IsSupported = 0 }; }; +template<> struct QAtomicOpsSupport<4> { enum { IsSupported = 1 }; }; template struct QAtomicAdditiveType { -- cgit v1.2.3