diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-06-24 09:23:47 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-07-06 17:56:58 +0200 |
commit | 0587d4752d8fb814d47a599130d98724d78b1525 (patch) | |
tree | 41199b3cc239c15297e3028a7c23640d3fff5d52 /src/corelib | |
parent | c0385f0cee52a5bb17e95cbdedda3dbff5f60b53 (diff) |
Remove uses of Q_ATOMIC_INT{8,16,32}_IS_SUPPORTED
It's always true these days, assert so in qatomic.cpp and
tst_QAtomicInteger.
Update the docs.
Pick-to: 6.4
Change-Id: I3684cff96c1d2e05677314e29514cc279bd6b1a1
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qloggingcategory.cpp | 19 | ||||
-rw-r--r-- | src/corelib/io/qloggingcategory.h | 16 | ||||
-rw-r--r-- | src/corelib/thread/qatomic.cpp | 38 |
3 files changed, 25 insertions, 48 deletions
diff --git a/src/corelib/io/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp index 201a50317b..bdae7e7f50 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 @@ -291,17 +279,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 ae8425142a..ca606bfae5 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<bool> enabledDebug; QBasicAtomicInteger<bool> enabledWarning; QBasicAtomicInteger<bool> enabledCritical; QBasicAtomicInteger<bool> enabledInfo; -#endif }; union { AtomicBools bools; diff --git a/src/corelib/thread/qatomic.cpp b/src/corelib/thread/qatomic.cpp index 8c0424c32c..0184774b44 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<quintptr>)); static_assert(sizeof(QAtomicInteger<qptrdiff>)); static_assert(sizeof(QAtomicInteger<char32_t>)); -#ifdef Q_ATOMIC_INT16_IS_SUPPORTED static_assert(sizeof(QAtomicInteger<short>)); static_assert(sizeof(QAtomicInteger<unsigned short>)); -# if WCHAR_MAX < 0x10000 static_assert(sizeof(QAtomicInteger<wchar_t>)); -# endif static_assert(sizeof(QAtomicInteger<char16_t>)); -#endif + +static_assert(sizeof(QAtomicInteger<char>)); +static_assert(sizeof(QAtomicInteger<unsigned char>)); +static_assert(sizeof(QAtomicInteger<signed char>)); +static_assert(sizeof(QAtomicInteger<bool>)); #ifdef Q_ATOMIC_INT64_IS_SUPPORTED static_assert(sizeof(QAtomicInteger<qint64>)); static_assert(sizeof(QAtomicInteger<quint64>)); #endif -#if WCHAR_MAX == INT_MAX -static_assert(sizeof(QAtomicInteger<wchar_t>)); -#endif - QT_END_NAMESPACE |