Can Q_GLOBAL_STATIC replace KStaticDelete ?
Thiago Macieira
thiago at kde.org
Wed Jan 17 18:38:44 GMT 2007
Matthias Kretz wrote:
>OK, I'm open for suggestions how to do it without
> q_atomic_test_and_set_ptr. For my use cases it wouldn't need to be
> thread safe...
There isn't one. It's either q_atomic_test_and_set_ptr or
QBasicAtomicPointer::testAndSet.
If your use-cases don't need to be thread-safe, you can do it like this:
#define K_GLOBAL_STATIC_NOT_THREADSAFE(TYPE, NAME) \
static TYPE *this_NAME; \
static void delete_NAME() \
{ \
delete this_NAME; \
this_NAME = 0; \
} \
\
static TYPE *NAME() \
{ \
if (!this_NAME) { \
this_NAME = new TYPE; \
qAddPostRoutine(delete_NAME)); \
} \
return this_NAME; \
}
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20070117/098501a3/attachment.sig>
More information about the kde-core-devel
mailing list