Can Q_GLOBAL_STATIC replace KStaticDelete ?

Matthias Kretz kretz at kde.org
Thu Jan 18 13:59:28 GMT 2007


On Thursday 18 January 2007 12:13, Thiago Macieira wrote:
> We cannot also rely on the C++ compiler having guards against reentrancy
> in static objects.

Meaning we may not rely on
static QGlobalStatic<TYPE > this_##NAME;
to be atomic? Q_GLOBAL_STATIC obviously relies on it. And if we already rely 
on it, why not do it without QAtomic:

template <typename T> class KGlobalStatic2
{
public:
    T* pointer;
    inline KGlobalStatic2() : pointer(new T) {}
    inline ~KGlobalStatic2()
    {
        delete pointer;
        pointer = 0;
    }
};
 
#define K_GLOBAL_STATIC_THREADSAFE(TYPE, NAME)                          \
    static TYPE *NAME()                                                 \
    {                                                                   \
        static KGlobalStatic2<TYPE > this_##NAME;                       \
        return this_##NAME.pointer;                                     \
    }
-- 
________________________________________________________
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/20070118/219daf55/attachment.sig>


More information about the kde-core-devel mailing list