Can Q_GLOBAL_STATIC replace KStaticDelete ?

Matthias Kretz kretz at kde.org
Wed Jan 17 20:18:41 GMT 2007


On Wednesday 17 January 2007 19:38, Thiago Macieira wrote:
> 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;			\
> 	}

Right, but that wouldn't clean up the static object if ~QCoreApplication isn't 
called. I need something that also gets cleaned up on lib unload.

So the extra Q/KGlobalStatic class is necessary also in this case.

Do we want a non-thread-safe solution for K_GLOBAL_STATIC then? Or can the 
trolls give us permission to use QAtomic-API? (I'm happy to use 
Q(Basic)AtomicPointer instead of q_atomic_test_and_set_ptr if that helps.)

-- 
________________________________________________________
Matthias Kretz (Germany)                            <><
http://Vir.homelinux.org/
MatthiasKretz at gmx.net, kretz at kde.org,
Matthias.Kretz at urz.uni-heidelberg.de
-------------- 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/d8d8a9f8/attachment.sig>


More information about the kde-core-devel mailing list