summaryrefslogtreecommitdiff
path: root/configmgr
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2011-05-30 15:30:27 +0100
committerCaolán McNamara <caolanm@redhat.com>2011-06-01 15:21:18 +0100
commit5a3c6e0a3dc07b09352203cccdae8bf60649f487 (patch)
treef403063b13fb4f2c758beb59638d8b9d633bdce4 /configmgr
parent205540afc1ab05763a8255873724bcbdbf9c0ba2 (diff)
use StaticWithArg
Diffstat (limited to 'configmgr')
-rw-r--r--configmgr/source/components.cxx26
-rw-r--r--configmgr/source/components.hxx3
-rw-r--r--configmgr/source/rootaccess.cxx3
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);
}