Can Q_GLOBAL_STATIC replace KStaticDelete ?
Matthias Kretz
kretz at kde.org
Thu Jan 18 12:01:30 GMT 2007
On Thursday 18 January 2007 00:48, Thiago Macieira wrote:
> Matthias Kretz wrote:
> >changes:
> >- removed K_GLOBAL_STATIC_WITH_ARGS in favor of putting all ctor and
> > dtor calls in the KGlobalStatic class so that singletons can declare
> > there ctor and dtor private/protected and make
> > KGlobalStatic<SingletonClass> a friend.
> > - replaced
> > q_atomic_test_and_set_ptr with QBasicAtomicPointer::testAndSet
>
> Problem with your patch:
> You're using an atomic test-and-set to make the object assignment
> thread-safe, but your KGlobal::addGlobalStatic isn't thread-safe.
Right. Not completely thought out... :(
> Either you make it fully thread-safe by adding a mutex protection around
> _globalStatics or you can drop thread safety and drop the QAtomic usage.
/me leans towards dropping thread safety for K_GLOBAL_STATIC. Use
Q_GLOBAL_STATIC if you want thread safety or if we really shouldn't use
Q_GLOBAL_STATIC like Simon wrote, create a K_GLOBAL_STATIC_THREADSAFE (or
so).
Dropping thread safety in K_GLOBAL_STATIC means that those statics may only be
initialized in the main thread. But that's the same we were expecting from
our KStaticDeleter deleted objects.
> If you add a mutex, you can drop QAtomic too, since you can protect the
> pointer assignment with the mutex. In the documentation, be sure to note
> that K_GLOBAL_STATIC will be slower than Q_GLOBAL_STATIC.
>
> Note: as an irony, the mutex must be Q_GLOBAL_STATIC :-)
Anybody thinks this would be a good idea?
> > - moved
> > public static variables of KGlobal into the .cpp file (making it
> > file-static) where possible
>
> Can you make another patch for that?
Yep, attached. Commit next monday? Or safe to commit now?
--
________________________________________________________
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: kglobal-cleanup.diff
Type: text/x-diff
Size: 3045 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20070118/8ecb8e80/attachment.diff>
-------------- 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/8ecb8e80/attachment.sig>
More information about the kde-core-devel
mailing list