diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2011-08-05 08:24:59 (GMT) |
---|---|---|
committer | João Abecasis <joao.abecasis@nokia.com> | 2011-08-11 16:58:08 (GMT) |
commit | c3b62edd3b3b8a231f13818f5722ad948d6f962b (patch) | |
tree | 6c78eb0edd688de65931f041bdb057eaf0c08983 /src/corelib | |
parent | c304667ae5364905e239c378a32d068ce5d6f8c9 (diff) | |
download | Qt-c3b62edd3b3b8a231f13818f5722ad948d6f962b.zip Qt-c3b62edd3b3b8a231f13818f5722ad948d6f962b.tar.gz Qt-c3b62edd3b3b8a231f13818f5722ad948d6f962b.tar.bz2 |
Re-introduce Q_GLOBAL_STATIC_INIT
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
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/global/qglobal.h | 37 |
1 files 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<TYPE > this_ ## NAME \ + = { Q_BASIC_ATOMIC_INITIALIZER(0), false } + #define Q_GLOBAL_STATIC(TYPE, NAME) \ static TYPE *NAME() \ { \ - static QGlobalStatic<TYPE > 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<TYPE > cleanup(thisGlobalStatic); \ + static QGlobalStaticDeleter<TYPE > cleanup(this__StaticVar_); \ } \ - return thisGlobalStatic.pointer; \ + return this__StaticVar_.pointer; \ } #define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \ static TYPE *NAME() \ { \ - static QGlobalStatic<TYPE > 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<TYPE > cleanup(thisGlobalStatic); \ + static QGlobalStaticDeleter<TYPE > cleanup(this__StaticVar_); \ } \ - return thisGlobalStatic.pointer; \ + return this__StaticVar_.pointer; \ } #define Q_GLOBAL_STATIC_WITH_INITIALIZER(TYPE, NAME, INITIALIZER) \ static TYPE *NAME() \ { \ - static QGlobalStatic<TYPE > 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<TYPE > x(new TYPE); \ INITIALIZER; \ - if (thisGlobalStatic.pointer.testAndSetOrdered(0, x.data())) { \ - static QGlobalStaticDeleter<TYPE > cleanup(thisGlobalStatic); \ + if (this__StaticVar_.pointer.testAndSetOrdered(0, x.data())) { \ + static QGlobalStaticDeleter<TYPE > cleanup(this__StaticVar_); \ x.take(); \ } \ } \ - return thisGlobalStatic.pointer; \ + return this__StaticVar_.pointer; \ } #endif |