Can Q_GLOBAL_STATIC replace KStaticDelete ?

Simon Hausmann hausmann at kde.org
Thu Jan 18 08:55:55 GMT 2007


On Wednesday 17 January 2007 21:18, Matthias Kretz wrote:
> 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.)

I just spoke with Brad and the bad news is: Do not use Q_GLOBAL_STATIC. It is 
going to change in the future. Also do /not/ use the q_atomic_with_underscore 
functions. They are going to change as well. Q(Basic)AtomicPointer is good to 
use though. (reasonably safe ;-)


Simon
-------------- 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/20070118/984d183b/attachment.sig>


More information about the kde-core-devel mailing list