From c3b62edd3b3b8a231f13818f5722ad948d6f962b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 5 Aug 2011 10:24:59 +0200 Subject: Re-introduce Q_GLOBAL_STATIC_INIT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing this macro in abff4d5090c1706c44485bbe3689a0e339c26a9b breaks code that used it in providing their own class-scope safe Q_GLOBAL_STATIC variations, the feature introduced in that commit. There may be other use cases for the macro. Anyway, even if this isn't part of the public API, there isn't a strong reason to remove the macro, so it is back now. Task-number: QTBUG-20627 Reviewed-by: Samuel Rødal --- src/corelib/global/qglobal.h | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 9c7f1c6..cfe5eea 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1924,50 +1924,51 @@ public: } }; +#define Q_GLOBAL_STATIC_INIT(TYPE, NAME) \ + static QGlobalStatic this_ ## NAME \ + = { Q_BASIC_ATOMIC_INITIALIZER(0), false } + #define Q_GLOBAL_STATIC(TYPE, NAME) \ static TYPE *NAME() \ { \ - static QGlobalStatic thisGlobalStatic \ - = { Q_BASIC_ATOMIC_INITIALIZER(0), false }; \ - if (!thisGlobalStatic.pointer && !thisGlobalStatic.destroyed) { \ + Q_GLOBAL_STATIC_INIT(TYPE, _StaticVar_); \ + if (!this__StaticVar_.pointer && !this__StaticVar_.destroyed) { \ TYPE *x = new TYPE; \ - if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) \ + if (!this__StaticVar_.pointer.testAndSetOrdered(0, x)) \ delete x; \ else \ - static QGlobalStaticDeleter cleanup(thisGlobalStatic); \ + static QGlobalStaticDeleter cleanup(this__StaticVar_); \ } \ - return thisGlobalStatic.pointer; \ + return this__StaticVar_.pointer; \ } #define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \ static TYPE *NAME() \ { \ - static QGlobalStatic thisGlobalStatic \ - = { Q_BASIC_ATOMIC_INITIALIZER(0), false }; \ - if (!thisGlobalStatic.pointer && !thisGlobalStatic.destroyed) { \ + Q_GLOBAL_STATIC_INIT(TYPE, _StaticVar_); \ + if (!this__StaticVar_.pointer && !this__StaticVar_.destroyed) { \ TYPE *x = new TYPE ARGS; \ - if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) \ + if (!this__StaticVar_.pointer.testAndSetOrdered(0, x)) \ delete x; \ else \ - static QGlobalStaticDeleter cleanup(thisGlobalStatic); \ + static QGlobalStaticDeleter cleanup(this__StaticVar_); \ } \ - return thisGlobalStatic.pointer; \ + return this__StaticVar_.pointer; \ } #define Q_GLOBAL_STATIC_WITH_INITIALIZER(TYPE, NAME, INITIALIZER) \ static TYPE *NAME() \ { \ - static QGlobalStatic thisGlobalStatic \ - = { Q_BASIC_ATOMIC_INITIALIZER(0), false }; \ - if (!thisGlobalStatic.pointer && !thisGlobalStatic.destroyed) { \ + Q_GLOBAL_STATIC_INIT(TYPE, _StaticVar_); \ + if (!this__StaticVar_.pointer && !this__StaticVar_.destroyed) { \ QScopedPointer x(new TYPE); \ INITIALIZER; \ - if (thisGlobalStatic.pointer.testAndSetOrdered(0, x.data())) { \ - static QGlobalStaticDeleter cleanup(thisGlobalStatic); \ + if (this__StaticVar_.pointer.testAndSetOrdered(0, x.data())) { \ + static QGlobalStaticDeleter cleanup(this__StaticVar_); \ x.take(); \ } \ } \ - return thisGlobalStatic.pointer; \ + return this__StaticVar_.pointer; \ } #endif -- cgit v0.12