diff options
Diffstat (limited to 'src/corelib/global/qglobalstatic.h')
-rw-r--r-- | src/corelib/global/qglobalstatic.h | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/corelib/global/qglobalstatic.h b/src/corelib/global/qglobalstatic.h index 3f626e88c1..93127adab3 100644 --- a/src/corelib/global/qglobalstatic.h +++ b/src/corelib/global/qglobalstatic.h @@ -4,6 +4,7 @@ #ifndef QGLOBALSTATIC_H #define QGLOBALSTATIC_H +#include <QtCore/qassert.h> #include <QtCore/qatomic.h> #include <QtCore/qtclasshelpermacros.h> @@ -39,9 +40,18 @@ template <typename QGS> union Holder ~Holder() { + // TSAN does not support atomic_thread_fence and GCC complains: + // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97868 + // https://github.com/google/sanitizers/issues/1352 +QT_WARNING_PUSH +#if defined(Q_CC_GNU_ONLY) && Q_CC_GNU >= 1100 +QT_WARNING_DISABLE_GCC("-Wtsan") +#endif + // import changes to *pointer() by other threads before running ~PlainType(): + std::atomic_thread_fence(std::memory_order_acquire); +QT_WARNING_POP pointer()->~PlainType(); - std::atomic_thread_fence(std::memory_order_acquire); // avoid mixing stores to guard and *pointer() - guard.storeRelaxed(QtGlobalStatic::Destroyed); + guard.storeRelease(QtGlobalStatic::Destroyed); } PlainType *pointer() noexcept @@ -73,13 +83,13 @@ template <typename Holder> struct QGlobalStatic } Type *operator->() { - Q_ASSERT_X(!isDestroyed(), "Q_GLOBAL_STATIC", + Q_ASSERT_X(!isDestroyed(), Q_FUNC_INFO, "The global static was used after being destroyed"); return instance(); } Type &operator*() { - Q_ASSERT_X(!isDestroyed(), "Q_GLOBAL_STATIC", + Q_ASSERT_X(!isDestroyed(), Q_FUNC_INFO, "The global static was used after being destroyed"); return *instance(); } |