From c9bfd34fa00eb349f6fc37cbea58b71d96a05138 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 6 Aug 2012 18:15:49 +0200 Subject: [PATCH] Enable QAtomicInteger for char16_t and char32_t Those are regular, integer types, of 16- and 32-bit width, respectively. C++11's std::atomic supports them, so we should too. C++11 also supports wchar_t, but since that type's size can change, I don't feel like support for it in Qt is pressing. Change-Id: I945b641c91a8a98be82715f878c382dee58ac98b Reviewed-by: Olivier Goffart --- src/corelib/arch/qatomic_armv6.h | 12 ++++++++++++ src/corelib/arch/qatomic_cxx11.h | 5 +++++ src/corelib/arch/qatomic_gcc.h | 3 +++ src/corelib/arch/qatomic_ia64.h | 5 +++++ src/corelib/arch/qatomic_mips.h | 13 +++++++++++++ src/corelib/arch/qatomic_msvc.h | 3 +++ src/corelib/arch/qatomic_x86.h | 6 ++++++ .../corelib/thread/qatomicint/tst_qatomicint.cpp | 8 ++++++++ 8 files changed, 55 insertions(+) diff --git a/src/corelib/arch/qatomic_armv6.h b/src/corelib/arch/qatomic_armv6.h index 1b13f84993..129c80eda8 100644 --- a/src/corelib/arch/qatomic_armv6.h +++ b/src/corelib/arch/qatomic_armv6.h @@ -74,6 +74,13 @@ QT_END_HEADER template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; +#if defined(Q_COMPILER_UNICODE_STRINGS) && !defined(Q_PROCESSOR_ARM_V6) +// for ARMv5, ensure that char32_t (an uint_least32_t), is 32-bit +// it's extremely unlikely it won't be on a 32-bit ARM, but just to be sure +// For ARMv6 and up, we're sure it works, but the definition is below +template<> struct QAtomicIntegerTraits +{ enum { IsInteger = sizeof(char32_t) == sizeof(int) ? 1 : -1 }; }; +#endif template struct QBasicAtomicOps: QGenericAtomicOps > { @@ -226,6 +233,11 @@ 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 }; }; +template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; +# endif + #define Q_ATOMIC_INT8_IS_SUPPORTED #define Q_ATOMIC_INT8_REFERENCE_COUNTING_IS_ALWAYS_NATIVE #define Q_ATOMIC_INT8_TEST_AND_SET_IS_ALWAYS_NATIVE diff --git a/src/corelib/arch/qatomic_cxx11.h b/src/corelib/arch/qatomic_cxx11.h index 46b94e4029..83160affd7 100644 --- a/src/corelib/arch/qatomic_cxx11.h +++ b/src/corelib/arch/qatomic_cxx11.h @@ -84,6 +84,11 @@ 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 }; }; +template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; +# endif + #define Q_ATOMIC_INT8_IS_SUPPORTED #define Q_ATOMIC_INT8_REFERENCE_COUNTING_IS_ALWAYS_NATIVE #define Q_ATOMIC_INT8_TEST_AND_SET_IS_ALWAYS_NATIVE diff --git a/src/corelib/arch/qatomic_gcc.h b/src/corelib/arch/qatomic_gcc.h index 2ceb0385ec..cb38dc89dd 100644 --- a/src/corelib/arch/qatomic_gcc.h +++ b/src/corelib/arch/qatomic_gcc.h @@ -57,6 +57,9 @@ QT_END_HEADER template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; +#ifdef Q_COMPILER_UNICODE_STRINGS +template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; +#endif #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_SOMETIMES_NATIVE #define Q_ATOMIC_INT_TEST_AND_SET_IS_SOMETIMES_NATIVE diff --git a/src/corelib/arch/qatomic_ia64.h b/src/corelib/arch/qatomic_ia64.h index c6387108e1..7f22bac582 100644 --- a/src/corelib/arch/qatomic_ia64.h +++ b/src/corelib/arch/qatomic_ia64.h @@ -138,6 +138,11 @@ 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 }; }; +template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; +# endif + template struct QBasicAtomicOps: QGenericAtomicOps > { template diff --git a/src/corelib/arch/qatomic_mips.h b/src/corelib/arch/qatomic_mips.h index e662b9abc2..718121cf65 100644 --- a/src/corelib/arch/qatomic_mips.h +++ b/src/corelib/arch/qatomic_mips.h @@ -74,6 +74,13 @@ QT_END_HEADER template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; +#if defined(Q_COMPILER_UNICODE_STRINGS) && !defined(Q_PROCESSOR_MIPS_64) +// for MIPS32, ensure that char32_t (an uint_least32_t), is 32-bit +// it's extremely unlikely it won't be on a 32-bit MIPS, but just to be sure +// For MIPS64, we're sure it works, but the definition is below +template<> struct QAtomicIntegerTraits +{ enum { IsInteger = sizeof(char32_t) == sizeof(int) ? 1 : -1 }; }; +#endif template struct QBasicAtomicOps: QGenericAtomicOps > { @@ -241,6 +248,12 @@ T QBasicAtomicOps<4>::fetchAndAddRelaxed(T &_q_value, typename QAtomicAdditiveTy 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<> 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 f5801a2939..41c526b9a6 100644 --- a/src/corelib/arch/qatomic_msvc.h +++ b/src/corelib/arch/qatomic_msvc.h @@ -266,6 +266,9 @@ 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 // No definition, needs specialization template struct QAtomicOpsBySize; diff --git a/src/corelib/arch/qatomic_x86.h b/src/corelib/arch/qatomic_x86.h index 094bf1ecb7..8fb83cd504 100644 --- a/src/corelib/arch/qatomic_x86.h +++ b/src/corelib/arch/qatomic_x86.h @@ -133,6 +133,12 @@ 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 }; }; +template<> struct QAtomicIntegerTraits { enum { IsInteger = 1 }; }; +# endif + + /* * Guide for the inline assembly below: * diff --git a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp index 1283083f0e..fbabb115a1 100644 --- a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp +++ b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp @@ -190,6 +190,10 @@ void tst_QAtomicInt::warningFreeHelper() warningFreeHelperTemplate >(); constexprFunctionsHelperTemplate >(); constexprFunctionsHelperTemplate >(); +# ifdef Q_COMPILER_UNICODE_STRINGS + warningFreeHelperTemplate >(); + constexprFunctionsHelperTemplate >(); +# endif #endif #ifdef Q_ATOMIC_INT16_IS_SUPPORTED @@ -197,6 +201,10 @@ void tst_QAtomicInt::warningFreeHelper() warningFreeHelperTemplate >(); constexprFunctionsHelperTemplate >(); constexprFunctionsHelperTemplate >(); +# ifdef Q_COMPILER_UNICODE_STRINGS + warningFreeHelperTemplate >(); + constexprFunctionsHelperTemplate >(); +# endif #endif #ifdef Q_ATOMIC_INT8_IS_SUPPORTED