From 5a3c6e0a3dc07b09352203cccdae8bf60649f487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Mon, 30 May 2011 15:30:27 +0100 Subject: [PATCH] use StaticWithArg --- configmgr/source/components.cxx | 26 ++++++++++---------------- configmgr/source/components.hxx | 3 ++- configmgr/source/rootaccess.cxx | 3 ++- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/configmgr/source/components.cxx b/configmgr/source/components.cxx index 8760946020f5..d4b3130ca9ed 100644 --- a/configmgr/source/components.cxx +++ b/configmgr/source/components.cxx @@ -57,6 +57,7 @@ #include "rtl/textenc.h" #include "rtl/ustring.h" #include "rtl/ustring.hxx" +#include "rtl/instance.hxx" #include "sal/types.h" #include "salhelper/simplereferenceobject.hxx" @@ -150,9 +151,6 @@ bool canRemoveFromLayer(int layer, rtl::Reference< Node > const & node) { } } -static bool singletonCreated = false; -static Components * singleton = 0; - } class Components::WriteThread: @@ -217,23 +215,19 @@ void Components::WriteThread::run() { reference_->clear(); } +class theComponentsSingleton : + public rtl::StaticWithArg< + Components, + css::uno::Reference< css::uno::XComponentContext >, + theComponentsSingleton> +{ +}; + Components & Components::getSingleton( css::uno::Reference< css::uno::XComponentContext > const & context) { OSL_ASSERT(context.is()); - if (!singletonCreated) { - static Components theSingleton(context); - singleton = &theSingleton; - singletonCreated = true; - } - if (singleton == 0) { - throw css::uno::RuntimeException( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( - "configmgr no Components singleton")), - css::uno::Reference< css::uno::XInterface >()); - } - return *singleton; + return theComponentsSingleton::get(context); } bool Components::allLocales(rtl::OUString const & locale) { diff --git a/configmgr/source/components.hxx b/configmgr/source/components.hxx index 9d216e1bb915..26af3fbdecea 100644 --- a/configmgr/source/components.hxx +++ b/configmgr/source/components.hxx @@ -123,12 +123,13 @@ private: typedef void FileParser( rtl::OUString const &, int, Data &, Partial const *, Modifications *, Additions *); - +public: Components( com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > const & context); ~Components(); +private: void parseFileLeniently( FileParser * parseFile, rtl::OUString const & url, int layer, diff --git a/configmgr/source/rootaccess.cxx b/configmgr/source/rootaccess.cxx index 90e5675b35a3..f320b999dcd2 100644 --- a/configmgr/source/rootaccess.cxx +++ b/configmgr/source/rootaccess.cxx @@ -130,7 +130,8 @@ bool RootAccess::isUpdate() const { return update_; } -RootAccess::~RootAccess() { +RootAccess::~RootAccess() +{ osl::MutexGuard g(*lock_); getComponents().removeRootAccess(this); }