diff options
author | Mike Achtelik <mike.achtelik@gmail.com> | 2021-10-18 13:35:15 +0200 |
---|---|---|
committer | Mike Achtelik <mike.achtelik@gmail.com> | 2021-11-18 20:53:27 +0100 |
commit | f7fd57075be0f504cad46e9a2e78caf3d54979af (patch) | |
tree | ed0c4739aff627488746d6fc973e4aee9da7ba33 /src/corelib/global/qglobalstatic.h | |
parent | 1a8b7eb1d4f27e74621ee94c01dbeda3afd302c7 (diff) |
Introduce Q_APPLICATION_STATIC
QObjects must be deleted if the QCoreApplication is being destroyed.
This was previously done by implementing custom code in qtbase and
other modules. So unify it and introduce a Q_APPLICATION_STATIC,
based on the Q_GLOBAL_STATIC, which centralises the logic.
Since we still have a few remaining living QObjects,
this comes in handy to fix those as well.
Task-number: QTBUG-84234
Change-Id: I3040a2280ff56291f2b1c39948c06a23597865c4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global/qglobalstatic.h')
-rw-r--r-- | src/corelib/global/qglobalstatic.h | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/corelib/global/qglobalstatic.h b/src/corelib/global/qglobalstatic.h index 49cebe1e61..6816721b32 100644 --- a/src/corelib/global/qglobalstatic.h +++ b/src/corelib/global/qglobalstatic.h @@ -57,6 +57,27 @@ enum GuardValues { }; } +#define Q_GLOBAL_STATIC_INTERNAL_HOLDER(ARGS) \ + struct HolderBase \ + { \ + HolderBase() = default; \ + ~HolderBase() noexcept \ + { \ + if (guard.loadRelaxed() == QtGlobalStatic::Initialized) \ + guard.storeRelaxed(QtGlobalStatic::Destroyed); \ + } \ + Q_DISABLE_COPY_MOVE(HolderBase) \ + }; \ + struct Holder : public HolderBase \ + { \ + Type value; \ + Holder() noexcept(noexcept(typename std::remove_cv<Type>::type ARGS)) \ + : value ARGS \ + { \ + guard.storeRelaxed(QtGlobalStatic::Initialized); \ + } \ + }; + #if defined(Q_OS_UNIX) && defined(Q_CC_INTEL) // Work around Intel issue ID 6000058488: // local statics inside an inline function inside an anonymous namespace are global @@ -69,24 +90,11 @@ enum GuardValues { #define Q_GLOBAL_STATIC_INTERNAL(ARGS) \ Q_GLOBAL_STATIC_INTERNAL_DECORATION Type *innerFunction() \ { \ - struct HolderBase { \ - HolderBase() = default; \ - ~HolderBase() noexcept \ - { if (guard.loadRelaxed() == QtGlobalStatic::Initialized) \ - guard.storeRelaxed(QtGlobalStatic::Destroyed); } \ - Q_DISABLE_COPY_MOVE(HolderBase) \ - }; \ - static struct Holder : public HolderBase { \ - Type value; \ - Holder() \ - noexcept(noexcept(typename std::remove_cv<Type>::type ARGS)) \ - : value ARGS \ - { guard.storeRelaxed(QtGlobalStatic::Initialized); } \ - } holder; \ + Q_GLOBAL_STATIC_INTERNAL_HOLDER(ARGS) \ + static Holder holder; \ return &holder.value; \ } - // this class must be POD, unless the compiler supports thread-safe statics template <typename T, T *(&innerFunction)(), QBasicAtomicInt &guard> struct QGlobalStatic |