[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice-devel
Subject: Re: [patch] koffice/libs/: port K3StaticDeleter to K_GLOBAL_STATIC
From: Jaroslaw Staniek <js () iidea ! pl>
Date: 2008-08-27 10:30:48
Message-ID: 48B52CD8.4090909 () iidea ! pl
[Download RAW message or body]
Thomas Zander said the following, On 2008-08-27 08:09:
> On Wednesday 27. August 2008 00:56:48 Jaroslaw Staniek wrote:
>> Hi,
>> Being bored with the warnings, I've finally ported K3StaticDeleters to
>> K_GLOBAL_STATICs. Since K_GLOBAL_STATIC overloads 'operator type*', I've
>> merged ctors with private ::init() method if there's any, to make the
>> code even simpler.
>> All the statics like s_instance are no put within the private (but still
>> static) usage of K_GLOBAL_STATIC within the blocks of instance() static
>> methods. This is the way how K_GLOBAL_STATIC is used in kdelibs too (and,
>> what's good, in our apps like KSpread).
>
> The reason I never did this is because as far as I understand it can't work
> with K_GLOBAL_STATIC; hopefully I'm wrong.
>
> The init and the constructor are separate for a good reason. The init
> fetches all the plugins and constructs them. So calling init can take quite
> some time.
> All the plugins do thing too, including calling another singleton. Which
> will then create lots of plugins there. And those plugins may use our
> singleton. And you have a loop.
K3StaticDeleter does not protect us for this - do you accept that the
singleton is accessed in somewhat uninitialized state (before init() ends)?
> Now, as far as I know a global-static only has a real pointer to it when the
> constructor finishes (basic OO, you can't use an object until its
> constructor finishes). So if I call instance() *from* the constructor,
> I've got a problem.
>
> And we do call instance() from the constructor in our 3rd party plugins, so
> we do need an init() method.
> If we can do that using K_GLOBAL_STATIC; great. But I've been told by the
> author that its not possible.
So I propose to keep init() and go with K_GLOBAL_STATIC; which works just like
the old static deleter in this case. Plus appropriate comments would be added
on why we need init().
Example:
KoShapeRegistry* KoShapeRegistry::instance()
{
K_GLOBAL_STATIC(KoShapeRegistry, s_singleton)
if (!s_singleton->exists())
s_singleton->init();
return s_singleton;
}
OK?
--
regards / pozdrawiam, Jaroslaw Staniek
Sponsored by OpenOffice Polska (http://www.openoffice.com.pl/en) to work on
Kexi & KOffice (http://www.kexi.pl/en, http://www.koffice.org/kexi)
KDE Libraries for MS Windows (http://windows.kde.org)
_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic