From e3e2674100b1ecbad7117f15c7aa13a704a7d34e Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 14 Dec 2021 09:03:55 -0300 Subject: [PATCH] QGlobalStatic: invert the order of destruction and setting the guard This is how the old implementation did it: the Type member was a member of Holder, but the guard was set to Destroyed in the HolderBase destructor, which ran after. I find the way I implemented in commit81a31beeb25eaf14d5c5f42fe26aa49d6ef29bf8 to be more natural, but it caused regressions at runtime for code that attempted to reenter the global static on destruction. Not unit-tested because I don't know if we want to keep this forever. Pick-to: 6.3 Fixes: QTBUG-99192 Change-Id: Ib42b3adc93bf4d43bd55fffd16c09d7f835d121e Reviewed-by: Marc Mutz --- src/corelib/global/qglobalstatic.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/global/qglobalstatic.h b/src/corelib/global/qglobalstatic.h index 098aee966b2..1e35cb29f05 100644 --- a/src/corelib/global/qglobalstatic.h +++ b/src/corelib/global/qglobalstatic.h @@ -76,9 +76,9 @@ template union Holder ~Holder() { - guard.storeRelaxed(QtGlobalStatic::Destroyed); - std::atomic_thread_fence(std::memory_order_acquire); // avoid mixing stores to guard and *pointer() pointer()->~PlainType(); + std::atomic_thread_fence(std::memory_order_acquire); // avoid mixing stores to guard and *pointer() + guard.storeRelaxed(QtGlobalStatic::Destroyed); } PlainType *pointer() noexcept