[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:       Thomas Zander <zander () kde ! org>
Date:       2008-08-27 12:54:42
Message-ID: 200808271454.45582.zander () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


On Wednesday 27. August 2008 12:30:48 Jaroslaw Staniek wrote:
> > 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)?

We have a guard that init is called only once, so subsequent calls to the 
somewhat uninitialized repository is ok.

> 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;
> }

Hmm, where does 'exists()' come from?  I can't find it in the API docs.
If this code makes sure that only the first time the singleton is created will 
it be initialized; thats exactly what we should have.
If so, sounds great :)

> BTW, looks like neither the K3StaticDeleter solution nor K_GLOBAL_STATIC
> solution is thread-safe - init() could be called many times...

KOffice is not made to be threadsafe. (just small parts are ;)
The issue I pointed out is with recursively calling instance(), but all from 
one thread.

-- 
Thomas Zander

["signature.asc" (application/pgp-signature)]

_______________________________________________
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