summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qglobalstatic.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/global/qglobalstatic.h')
-rw-r--r--src/corelib/global/qglobalstatic.h21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/corelib/global/qglobalstatic.h b/src/corelib/global/qglobalstatic.h
index d865e08fdd..93127adab3 100644
--- a/src/corelib/global/qglobalstatic.h
+++ b/src/corelib/global/qglobalstatic.h
@@ -1,12 +1,12 @@
// Copyright (C) 2021 Intel Corporation.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-#include <QtCore/qglobal.h>
-
#ifndef QGLOBALSTATIC_H
#define QGLOBALSTATIC_H
+#include <QtCore/qassert.h>
#include <QtCore/qatomic.h>
+#include <QtCore/qtclasshelpermacros.h>
#include <atomic> // for bootstrapped (no thread) builds
#include <type_traits>
@@ -40,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
@@ -74,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();
}