diff --git a/src/corelib/io/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp index 08b7b2d5848..8136b5f545c 100644 --- a/src/corelib/io/qloggingcategory.cpp +++ b/src/corelib/io/qloggingcategory.cpp @@ -9,18 +9,6 @@ QT_BEGIN_NAMESPACE const char qtDefaultCategoryName[] = "default"; Q_GLOBAL_STATIC(QLoggingCategory, qtDefaultCategory, qtDefaultCategoryName) -#ifndef Q_ATOMIC_INT8_IS_SUPPORTED -static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift) -{ - const int bit = 1 << shift; - - if (enable) - atomic->fetchAndOrRelaxed(bit); - else - atomic->fetchAndAndRelaxed(~bit); -} -#endif - /*! \class QLoggingCategory \inmodule QtCore @@ -288,17 +276,10 @@ bool QLoggingCategory::isEnabled(QtMsgType msgtype) const void QLoggingCategory::setEnabled(QtMsgType type, bool enable) { switch (type) { -#ifdef Q_ATOMIC_INT8_IS_SUPPORTED case QtDebugMsg: bools.enabledDebug.storeRelaxed(enable); break; case QtInfoMsg: bools.enabledInfo.storeRelaxed(enable); break; case QtWarningMsg: bools.enabledWarning.storeRelaxed(enable); break; case QtCriticalMsg: bools.enabledCritical.storeRelaxed(enable); break; -#else - case QtDebugMsg: setBoolLane(&enabled, enable, DebugShift); break; - case QtInfoMsg: setBoolLane(&enabled, enable, InfoShift); break; - case QtWarningMsg: setBoolLane(&enabled, enable, WarningShift); break; - case QtCriticalMsg: setBoolLane(&enabled, enable, CriticalShift); break; -#endif case QtFatalMsg: break; } } diff --git a/src/corelib/io/qloggingcategory.h b/src/corelib/io/qloggingcategory.h index 60773bd2a92..2b628c6f7a5 100644 --- a/src/corelib/io/qloggingcategory.h +++ b/src/corelib/io/qloggingcategory.h @@ -19,17 +19,11 @@ public: bool isEnabled(QtMsgType type) const; void setEnabled(QtMsgType type, bool enable); -#ifdef Q_ATOMIC_INT8_IS_SUPPORTED bool isDebugEnabled() const { return bools.enabledDebug.loadRelaxed(); } bool isInfoEnabled() const { return bools.enabledInfo.loadRelaxed(); } bool isWarningEnabled() const { return bools.enabledWarning.loadRelaxed(); } bool isCriticalEnabled() const { return bools.enabledCritical.loadRelaxed(); } -#else - bool isDebugEnabled() const { return enabled.loadRelaxed() >> DebugShift & 1; } - bool isInfoEnabled() const { return enabled.loadRelaxed() >> InfoShift & 1; } - bool isWarningEnabled() const { return enabled.loadRelaxed() >> WarningShift & 1; } - bool isCriticalEnabled() const { return enabled.loadRelaxed() >> CriticalShift & 1; } -#endif + const char *categoryName() const { return name; } // allows usage of both factory method and variable in qCX macros @@ -49,19 +43,11 @@ private: Q_DECL_UNUSED_MEMBER void *d; // reserved for future use const char *name; -#ifdef Q_BIG_ENDIAN - enum { DebugShift = 0, WarningShift = 8, CriticalShift = 16, InfoShift = 24 }; -#else - enum { DebugShift = 24, WarningShift = 16, CriticalShift = 8, InfoShift = 0}; -#endif - struct AtomicBools { -#ifdef Q_ATOMIC_INT8_IS_SUPPORTED QBasicAtomicInteger enabledDebug; QBasicAtomicInteger enabledWarning; QBasicAtomicInteger enabledCritical; QBasicAtomicInteger enabledInfo; -#endif }; union { AtomicBools bools; diff --git a/src/corelib/thread/qatomic.cpp b/src/corelib/thread/qatomic.cpp index 8c0424c32c6..0184774b447 100644 --- a/src/corelib/thread/qatomic.cpp +++ b/src/corelib/thread/qatomic.cpp @@ -39,11 +39,11 @@ \li pointer size: qintptr, quintptr, qptrdiff \endlist - Of the list above, only the 32-bit- and pointer-sized instantiations are guaranteed to - work on all platforms. Support for other sizes depends on the compiler and - processor architecture the code is being compiled for. To test whether the - other types are supported, check the macro \c Q_ATOMIC_INT\e{nn}_IS_SUPPORTED, - where \c{\e{nn}} is the number of bits desired. + Of the list above, only the 8-bit, 16-bit, 32-bit- and pointer-sized + instantiations are guaranteed to work on all platforms. Support for other + sizes depends on the compiler and processor architecture the code is being + compiled for. To test whether the 64-bit types are supported on 32-bit + platforms, check the macro \c Q_ATOMIC_INT64_IS_SUPPORTED. \section1 The Atomic API @@ -950,9 +950,16 @@ This macro is defined if atomic integers of size \e{nn} (in bits) are supported in this compiler / architecture combination. - Q_ATOMIC_INT32_IS_SUPPORTED is always defined. \e{nn} is the size of the integer, in bits (8, 16, 32 or 64). + + The following macros always defined: + + \list + \li Q_ATOMIC_INT8_IS_SUPPORTED + \li Q_ATOMIC_INT16_IS_SUPPORTED + \li Q_ATOMIC_INT32_IS_SUPPORTED + \endlist */ /*! @@ -1653,6 +1660,12 @@ */ // static checks +#ifndef Q_ATOMIC_INT8_IS_SUPPORTED +# error "Q_ATOMIC_INT8_IS_SUPPORTED must be defined" +#endif +#ifndef Q_ATOMIC_INT16_IS_SUPPORTED +# error "Q_ATOMIC_INT16_IS_SUPPORTED must be defined" +#endif #ifndef Q_ATOMIC_INT32_IS_SUPPORTED # error "Q_ATOMIC_INT32_IS_SUPPORTED must be defined" #endif @@ -1671,22 +1684,19 @@ static_assert(sizeof(QAtomicInteger)); static_assert(sizeof(QAtomicInteger)); static_assert(sizeof(QAtomicInteger)); -#ifdef Q_ATOMIC_INT16_IS_SUPPORTED static_assert(sizeof(QAtomicInteger)); static_assert(sizeof(QAtomicInteger)); -# if WCHAR_MAX < 0x10000 static_assert(sizeof(QAtomicInteger)); -# endif static_assert(sizeof(QAtomicInteger)); -#endif + +static_assert(sizeof(QAtomicInteger)); +static_assert(sizeof(QAtomicInteger)); +static_assert(sizeof(QAtomicInteger)); +static_assert(sizeof(QAtomicInteger)); #ifdef Q_ATOMIC_INT64_IS_SUPPORTED static_assert(sizeof(QAtomicInteger)); static_assert(sizeof(QAtomicInteger)); #endif -#if WCHAR_MAX == INT_MAX -static_assert(sizeof(QAtomicInteger)); -#endif - QT_END_NAMESPACE diff --git a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp index 3d1b96a8966..b99e5f75f54 100644 --- a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp +++ b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp @@ -161,23 +161,19 @@ void tst_QAtomicInt::warningFreeHelper() constexprFunctionsHelperTemplate >(); constexprFunctionsHelperTemplate >(); -#ifdef Q_ATOMIC_INT16_IS_SUPPORTED warningFreeHelperTemplate >(); warningFreeHelperTemplate >(); constexprFunctionsHelperTemplate >(); constexprFunctionsHelperTemplate >(); warningFreeHelperTemplate >(); constexprFunctionsHelperTemplate >(); -#endif -#ifdef Q_ATOMIC_INT8_IS_SUPPORTED warningFreeHelperTemplate >(); warningFreeHelperTemplate >(); warningFreeHelperTemplate >(); constexprFunctionsHelperTemplate >(); constexprFunctionsHelperTemplate >(); constexprFunctionsHelperTemplate >(); -#endif #ifdef Q_ATOMIC_INT64_IS_SUPPORTED #if !defined(__i386__) || (defined(Q_CC_GNU) && defined(__OPTIMIZE__)) @@ -205,17 +201,9 @@ void tst_QAtomicInt::alignment() static_assert(alignof(QBasicAtomicInt) == alignof(TypeInStruct)); static_assert(alignof(QBasicAtomicInt) == alignof(TypeInStruct)); -#ifdef Q_ATOMIC_INT32_IS_SUPPORTED QCOMPARE(alignof(QBasicAtomicInteger), alignof(TypeInStruct)); -#endif - -#ifdef Q_ATOMIC_INT16_IS_SUPPORTED QCOMPARE(alignof(QBasicAtomicInteger), alignof(TypeInStruct)); -#endif - -#ifdef Q_ATOMIC_INT8_IS_SUPPORTED QCOMPARE(alignof(QBasicAtomicInteger), alignof(TypeInStruct)); -#endif #if !defined(Q_PROCESSOR_X86_32) && defined(Q_ATOMIC_INT64_IS_SUPPORTED) // The alignment is different on x86_32 @@ -493,7 +481,6 @@ void tst_QAtomicInt::testAndSet() QTEST(atomic.testAndSetOrdered(expected, newval), "result"); } -#ifdef Q_ATOMIC_INT32_IS_SUPPORTED QFETCH(bool, result); // the new implementation has the version that loads the current value @@ -528,7 +515,6 @@ void tst_QAtomicInt::testAndSet() if (!result) QCOMPARE(currentval, value); } -#endif } void tst_QAtomicInt::isFetchAndStoreNative() diff --git a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp index 61f0697d6c8..9d7a71e7e70 100644 --- a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp +++ b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp @@ -32,6 +32,12 @@ #include #include +#if !defined(Q_ATOMIC_INT8_IS_SUPPORTED) +# error "QAtomicInteger for 8-bit types must be supported!" +#endif +#if !defined(Q_ATOMIC_INT16_IS_SUPPORTED) +# error "QAtomicInteger for 16-bit types must be supported!" +#endif #if !defined(Q_ATOMIC_INT32_IS_SUPPORTED) # error "QAtomicInteger for 32-bit types must be supported!" #endif @@ -40,31 +46,21 @@ #endif // always supported types: +#define TYPE_SUPPORTED_char 1 +#define TYPE_SUPPORTED_uchar 1 +#define TYPE_SUPPORTED_schar 1 +#define TYPE_SUPPORTED_short 1 +#define TYPE_SUPPORTED_ushort 1 +#define TYPE_SUPPORTED_char16_t 1 +#define TYPE_SUPPORTED_wchar_t 1 #define TYPE_SUPPORTED_int 1 #define TYPE_SUPPORTED_uint 1 #define TYPE_SUPPORTED_long 1 #define TYPE_SUPPORTED_ulong 1 #define TYPE_SUPPORTED_qptrdiff 1 #define TYPE_SUPPORTED_quintptr 1 -#if (defined(__SIZEOF_WCHAR_T__) && (__SIZEOF_WCHAR_T__-0) > 2) \ - || (defined(WCHAR_MAX) && (WCHAR_MAX-0 > 0x10000)) -# define TYPE_SUPPORTED_wchar_t 1 -#endif -#define TYPE_SUPPORTED_char32_t 1 +#define TYPE_SUPPORTED_char32_t 1 -#ifdef Q_ATOMIC_INT8_IS_SUPPORTED -# define TYPE_SUPPORTED_char 1 -# define TYPE_SUPPORTED_uchar 1 -# define TYPE_SUPPORTED_schar 1 -#endif -#ifdef Q_ATOMIC_INT16_IS_SUPPORTED -# define TYPE_SUPPORTED_short 1 -# define TYPE_SUPPORTED_ushort 1 -# define TYPE_SUPPORTED_char16_t 1 -# ifndef TYPE_SUPPORTED_wchar_t -# define TYPE_SUPPORTED_wchar_t 1 -# endif -#endif #ifdef Q_ATOMIC_INT64_IS_SUPPORTED # define TYPE_SUPPORTED_qlonglong 1 # define TYPE_SUPPORTED_qulonglong 1