[Libreoffice-commits] core.git: configmgr/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Thu Jan 2 18:07:53 UTC 2020


 configmgr/source/access.cxx                |   94 ++++++++++++++---------------
 configmgr/source/access.hxx                |    2 
 configmgr/source/childaccess.cxx           |   16 ++--
 configmgr/source/childaccess.hxx           |    1 
 configmgr/source/components.cxx            |   11 ++-
 configmgr/source/components.hxx            |    1 
 configmgr/source/configurationprovider.cxx |   15 ++--
 configmgr/source/defaultprovider.cxx       |    2 
 configmgr/source/lock.cxx                  |   12 ++-
 configmgr/source/lock.hxx                  |    3 
 configmgr/source/readonlyaccess.cxx        |    2 
 configmgr/source/readwriteaccess.cxx       |    2 
 configmgr/source/rootaccess.cxx            |   17 ++---
 configmgr/source/rootaccess.hxx            |    2 
 configmgr/source/update.cxx                |   10 +--
 15 files changed, 105 insertions(+), 85 deletions(-)

New commits:
commit cb109d6518cc36155f9d0665932de0a54fdb6f4a
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Jan 2 08:05:01 2020 +0100
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Jan 2 19:07:20 2020 +0100

    Revert "no need to use shared_ptr here"
    
    This reverts commit 122598af564082786f01b4eafdb9f09f0cffdf5f.
    
    Reason for revert: shared_ptr was introduced for fdo#31494, to avoid issues during shutdown
    
    Change-Id: I1c3ef4a966b9244da1e504806e917d1918b83803
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86095
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/configmgr/source/access.cxx b/configmgr/source/access.cxx
index 0564cb3bad88..9fe7f31cc00f 100644
--- a/configmgr/source/access.cxx
+++ b/configmgr/source/access.cxx
@@ -171,7 +171,7 @@ void Access::initBroadcaster(
 css::uno::Sequence< css::uno::Type > Access::getTypes()
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     std::vector< css::uno::Type > types;
     types.push_back(cppu::UnoType< css::uno::XInterface >::get());
@@ -222,7 +222,7 @@ css::uno::Sequence< css::uno::Type > Access::getTypes()
 css::uno::Sequence< sal_Int8 > Access::getImplementationId()
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return css::uno::Sequence< sal_Int8 >();
 }
@@ -230,7 +230,7 @@ css::uno::Sequence< sal_Int8 > Access::getImplementationId()
 OUString Access::getImplementationName()
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return "org.openoffice-configmgr::Access";
 }
@@ -243,7 +243,7 @@ sal_Bool Access::supportsService(OUString const & ServiceName)
 css::uno::Sequence< OUString > Access::getSupportedServiceNames()
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     std::vector<OUString> services;
     services.emplace_back("com.sun.star.configuration.ConfigurationAccess");
@@ -274,7 +274,7 @@ void Access::dispose() {
     assert(thisIs(IS_ANY));
     Broadcaster bc;
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         if (getParentAccess().is()) {
             throw css::uno::RuntimeException(
@@ -296,7 +296,7 @@ void Access::addEventListener(
 {
     assert(thisIs(IS_ANY));
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         if (!xListener.is()) {
             throw css::uno::RuntimeException(
@@ -317,7 +317,7 @@ void Access::removeEventListener(
     css::uno::Reference< css::lang::XEventListener > const & aListener)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     DisposeListeners::iterator i(disposeListeners_.find(aListener));
     if (i != disposeListeners_.end()) {
@@ -327,7 +327,7 @@ void Access::removeEventListener(
 
 css::uno::Type Access::getElementType() {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     rtl::Reference< Node > p(getNode());
     switch (p->kind()) {
@@ -350,7 +350,7 @@ css::uno::Type Access::getElementType() {
 
 sal_Bool Access::hasElements() {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return !getAllChildren().empty(); //TODO: optimize
 }
@@ -394,7 +394,7 @@ bool Access::getByNameFast(const OUString & name, css::uno::Any & value)
 css::uno::Any Access::getByName(OUString const & aName)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     css::uno::Any value;
     if (!getByNameFast(aName, value))
@@ -406,7 +406,7 @@ css::uno::Any Access::getByName(OUString const & aName)
 css::uno::Sequence< OUString > Access::getElementNames()
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     std::vector< rtl::Reference< ChildAccess > > children(getAllChildren());
     std::vector<OUString> names;
@@ -421,7 +421,7 @@ css::uno::Sequence< OUString > Access::getElementNames()
 sal_Bool Access::hasByName(OUString const & aName)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return getChild(aName).is();
 }
@@ -429,7 +429,7 @@ sal_Bool Access::hasByName(OUString const & aName)
 css::uno::Any Access::getByHierarchicalName(OUString const & aName)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     rtl::Reference< ChildAccess > child(getSubChild(aName));
     if (!child.is()) {
@@ -442,7 +442,7 @@ css::uno::Any Access::getByHierarchicalName(OUString const & aName)
 sal_Bool Access::hasByHierarchicalName(OUString const & aName)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return getSubChild(aName).is();
 }
@@ -454,7 +454,7 @@ void Access::replaceByHierarchicalName(
     assert(thisIs(IS_UPDATE));
     Broadcaster bc;
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         rtl::Reference< ChildAccess > child(getSubChild(aName));
         if (!child.is()) {
@@ -494,7 +494,7 @@ void Access::addContainerListener(
 {
     assert(thisIs(IS_ANY));
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         if (!xListener.is()) {
             throw css::uno::RuntimeException(
@@ -515,7 +515,7 @@ void Access::removeContainerListener(
     css::uno::Reference< css::container::XContainerListener > const & xListener)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     ContainerListeners::iterator i(containerListeners_.find(xListener));
     if (i != containerListeners_.end()) {
@@ -526,7 +526,7 @@ void Access::removeContainerListener(
 OUString Access::getExactName(OUString const & aApproximateName)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return aApproximateName;
 }
@@ -534,7 +534,7 @@ OUString Access::getExactName(OUString const & aApproximateName)
 css::uno::Sequence< css::beans::Property > Access::getProperties()
 {
     assert(thisIs(IS_GROUP));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     std::vector< rtl::Reference< ChildAccess > > children(getAllChildren());
     std::vector< css::beans::Property > properties;
     properties.reserve(children.size());
@@ -548,7 +548,7 @@ css::uno::Sequence< css::beans::Property > Access::getProperties()
 css::beans::Property Access::getPropertyByName(OUString const & aName)
 {
     assert(thisIs(IS_GROUP));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     rtl::Reference< ChildAccess > child(getChild(aName));
     if (!child.is()) {
         throw css::beans::UnknownPropertyException(
@@ -560,13 +560,13 @@ css::beans::Property Access::getPropertyByName(OUString const & aName)
 sal_Bool Access::hasPropertyByName(OUString const & Name)
 {
     assert(thisIs(IS_GROUP));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     return getChild(Name).is();
 }
 
 OUString Access::getHierarchicalName() {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     // For backwards compatibility, return an absolute path representation where
     // available:
@@ -588,7 +588,7 @@ OUString Access::composeHierarchicalName(
     OUString const & aRelativeName)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     if (aRelativeName.isEmpty() || aRelativeName[0] == '/') {
         throw css::lang::IllegalArgumentException(
@@ -605,7 +605,7 @@ OUString Access::composeHierarchicalName(
 
 OUString Access::getName() {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return getNameInternal();
 }
@@ -615,7 +615,7 @@ void Access::setName(OUString const & aName)
     assert(thisIs(IS_ANY));
     Broadcaster bc;
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         checkFinalized();
         Modifications localMods;
@@ -681,7 +681,7 @@ void Access::setName(OUString const & aName)
 css::beans::Property Access::getAsProperty()
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return asProperty();
 }
@@ -698,7 +698,7 @@ void Access::setPropertyValue(
     assert(thisIs(IS_GROUP));
     Broadcaster bc;
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         if (!getRootAccess()->isUpdate()) {
             throw css::uno::RuntimeException(
                 "configmgr setPropertyValue on non-update access",
@@ -717,7 +717,7 @@ void Access::setPropertyValue(
 css::uno::Any Access::getPropertyValue(OUString const & PropertyName)
 {
     assert(thisIs(IS_GROUP));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
 
     css::uno::Any value;
     if (!getByNameFast(PropertyName, value))
@@ -733,7 +733,7 @@ void Access::addPropertyChangeListener(
 {
     assert(thisIs(IS_GROUP));
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         if (!xListener.is()) {
             throw css::uno::RuntimeException(
                 "null listener", static_cast< cppu::OWeakObject * >(this));
@@ -756,7 +756,7 @@ void Access::removePropertyChangeListener(
         aListener)
 {
     assert(thisIs(IS_GROUP));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkKnownProperty(aPropertyName);
     PropertyChangeListeners::iterator i(
         propertyChangeListeners_.find(aPropertyName));
@@ -778,7 +778,7 @@ void Access::addVetoableChangeListener(
 {
     assert(thisIs(IS_GROUP));
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         if (!aListener.is()) {
             throw css::uno::RuntimeException(
                 "null listener", static_cast< cppu::OWeakObject * >(this));
@@ -802,7 +802,7 @@ void Access::removeVetoableChangeListener(
         aListener)
 {
     assert(thisIs(IS_GROUP));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkKnownProperty(PropertyName);
     VetoableChangeListeners::iterator i(
         vetoableChangeListeners_.find(PropertyName));
@@ -824,7 +824,7 @@ void Access::setPropertyValues(
     assert(thisIs(IS_GROUP));
     Broadcaster bc;
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         if (!getRootAccess()->isUpdate()) {
             throw css::uno::RuntimeException(
                 "configmgr setPropertyValues on non-update access",
@@ -853,7 +853,7 @@ css::uno::Sequence< css::uno::Any > Access::getPropertyValues(
     css::uno::Sequence< OUString > const & aPropertyNames)
 {
     assert(thisIs(IS_GROUP));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     css::uno::Sequence< css::uno::Any > vals(aPropertyNames.getLength());
 
     for (sal_Int32 i = 0; i < aPropertyNames.getLength(); ++i)
@@ -874,7 +874,7 @@ void Access::addPropertiesChangeListener(
 {
     assert(thisIs(IS_GROUP));
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         if (!xListener.is()) {
             throw css::uno::RuntimeException(
                 "null listener", static_cast< cppu::OWeakObject * >(this));
@@ -895,7 +895,7 @@ void Access::removePropertiesChangeListener(
         xListener)
 {
     assert(thisIs(IS_GROUP));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     PropertiesChangeListeners::iterator i(
         propertiesChangeListeners_.find(xListener));
     if (i != propertiesChangeListeners_.end()) {
@@ -933,7 +933,7 @@ void Access::setHierarchicalPropertyValue(
     assert(thisIs(IS_GROUP));
     Broadcaster bc;
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         if (!getRootAccess()->isUpdate()) {
             throw css::uno::RuntimeException(
                 "configmgr setHierarchicalPropertyName on non-update access",
@@ -958,7 +958,7 @@ css::uno::Any Access::getHierarchicalPropertyValue(
     OUString const & aHierarchicalPropertyName)
 {
     assert(thisIs(IS_GROUP));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     rtl::Reference< ChildAccess > child(getSubChild(aHierarchicalPropertyName));
     if (!child.is()) {
         throw css::beans::UnknownPropertyException(
@@ -975,7 +975,7 @@ void Access::setHierarchicalPropertyValues(
     assert(thisIs(IS_GROUP));
     Broadcaster bc;
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         if (!getRootAccess()->isUpdate()) {
             throw css::uno::RuntimeException(
                 "configmgr setPropertyValues on non-update access",
@@ -1009,7 +1009,7 @@ css::uno::Sequence< css::uno::Any > Access::getHierarchicalPropertyValues(
     css::uno::Sequence< OUString > const & aHierarchicalPropertyNames)
 {
     assert(thisIs(IS_GROUP));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     css::uno::Sequence< css::uno::Any > vals(
         aHierarchicalPropertyNames.getLength());
     for (sal_Int32 i = 0; i < aHierarchicalPropertyNames.getLength(); ++i) {
@@ -1030,7 +1030,7 @@ css::beans::Property Access::getPropertyByHierarchicalName(
     OUString const & aHierarchicalName)
 {
     assert(thisIs(IS_GROUP));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     rtl::Reference< ChildAccess > child(getSubChild(aHierarchicalName));
     if (!child.is()) {
         throw css::beans::UnknownPropertyException(
@@ -1043,7 +1043,7 @@ sal_Bool Access::hasPropertyByHierarchicalName(
     OUString const & aHierarchicalName)
 {
     assert(thisIs(IS_GROUP));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     return getSubChild(aHierarchicalName).is();
 }
 
@@ -1053,7 +1053,7 @@ void Access::replaceByName(
     assert(thisIs(IS_UPDATE));
     Broadcaster bc;
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         rtl::Reference< ChildAccess > child(getChild(aName));
         if (!child.is()) {
@@ -1093,7 +1093,7 @@ void Access::insertByName(
     assert(thisIs(IS_EXTENSIBLE|IS_UPDATE));
     Broadcaster bc;
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         checkFinalized();
         if (getChild(aName).is()) {
@@ -1152,7 +1152,7 @@ void Access::removeByName(OUString const & aName)
     assert(thisIs(IS_EXTENSIBLE|IS_UPDATE));
     Broadcaster bc;
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         rtl::Reference< ChildAccess > child(getChild(aName));
         if (!child.is() || child->isFinalized() ||
@@ -1213,7 +1213,7 @@ css::uno::Reference< css::uno::XInterface > Access::createInstanceWithArguments(
 }
 
 Access::Access(Components & components):
-    components_(components), disposed_(false)
+    components_(components), disposed_(false), lock_( lock() )
 {
 }
 
@@ -2193,7 +2193,7 @@ rtl::Reference< Access > Access::getNotificationRoot() {
 
 #if !defined NDEBUG
 bool Access::thisIs(int what) {
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     rtl::Reference< Node > p(getNode());
     Node::Kind k(p->kind());
     return (k != Node::KIND_PROPERTY && k != Node::KIND_LOCALIZED_VALUE &&
diff --git a/configmgr/source/access.hxx b/configmgr/source/access.hxx
index db2decb48874..5c6075ecbf6d 100644
--- a/configmgr/source/access.hxx
+++ b/configmgr/source/access.hxx
@@ -435,6 +435,8 @@ private:
     PropertiesChangeListeners propertiesChangeListeners_;
     bool disposed_;
 
+    std::shared_ptr<osl::Mutex> lock_;
+
 #if !defined NDEBUG
 protected:
     enum {
diff --git a/configmgr/source/childaccess.cxx b/configmgr/source/childaccess.cxx
index 65cb9fc2e53f..68bc0b01351c 100644
--- a/configmgr/source/childaccess.cxx
+++ b/configmgr/source/childaccess.cxx
@@ -70,7 +70,8 @@ ChildAccess::ChildAccess(
     rtl::Reference< Access > const & parent, OUString const & name,
     rtl::Reference< Node > const & node):
     Access(components), root_(root), parent_(parent), name_(name), node_(node),
-    inTransaction_(false)
+    inTransaction_(false),
+    lock_( lock() )
 {
     assert(root.is() && parent.is() && node.is());
 }
@@ -78,7 +79,8 @@ ChildAccess::ChildAccess(
 ChildAccess::ChildAccess(
     Components & components, rtl::Reference< RootAccess > const & root,
     rtl::Reference< Node > const & node):
-    Access(components), root_(root), node_(node), inTransaction_(false)
+    Access(components), root_(root), node_(node), inTransaction_(false),
+    lock_( lock() )
 {
     assert(root.is() && node.is());
 }
@@ -146,7 +148,7 @@ void ChildAccess::release() throw () {
 css::uno::Reference< css::uno::XInterface > ChildAccess::getParent()
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return static_cast< cppu::OWeakObject * >(parent_.get());
 }
@@ -154,7 +156,7 @@ css::uno::Reference< css::uno::XInterface > ChildAccess::getParent()
 void ChildAccess::setParent(css::uno::Reference< css::uno::XInterface > const &)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     throw css::lang::NoSupportException(
         "setParent", static_cast< cppu::OWeakObject * >(this));
@@ -164,7 +166,7 @@ sal_Int64 ChildAccess::getSomething(
     css::uno::Sequence< sal_Int8 > const & aIdentifier)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return aIdentifier == getTunnelId()
         ? reinterpret_cast< sal_Int64 >(this) : 0;
@@ -312,7 +314,7 @@ void ChildAccess::commitChanges(bool valid, Modifications * globalModifications)
 }
 
 ChildAccess::~ChildAccess() {
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     if (parent_.is()) {
         parent_->releaseChild(name_);
     }
@@ -337,7 +339,7 @@ void ChildAccess::addSupportedServiceNames(
 css::uno::Any ChildAccess::queryInterface(css::uno::Type const & aType)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     css::uno::Any res(Access::queryInterface(aType));
     return res.hasValue()
diff --git a/configmgr/source/childaccess.hxx b/configmgr/source/childaccess.hxx
index 96f7f439f8c4..7a5a692d56a9 100644
--- a/configmgr/source/childaccess.hxx
+++ b/configmgr/source/childaccess.hxx
@@ -129,6 +129,7 @@ private:
     std::unique_ptr< css::uno::Any > changedValue_;
     bool inTransaction_;
         // to determine if a free node can be inserted underneath some root
+    std::shared_ptr<osl::Mutex> lock_;
 };
 
 }
diff --git a/configmgr/source/components.cxx b/configmgr/source/components.cxx
index 60b74f8d18f0..939d226e964d 100644
--- a/configmgr/source/components.cxx
+++ b/configmgr/source/components.cxx
@@ -164,20 +164,22 @@ private:
     OUString url_;
     Data const & data_;
     osl::Condition delay_;
+    std::shared_ptr<osl::Mutex> lock_;
 };
 
 Components::WriteThread::WriteThread(
     rtl::Reference< WriteThread > * reference, Components & components,
     OUString const & url, Data const & data):
     Thread("configmgrWriter"), reference_(reference), components_(components),
-    url_(url), data_(data)
+    url_(url), data_(data),
+    lock_( lock() )
 {
     assert(reference != nullptr);
 }
 
 void Components::WriteThread::execute() {
     delay_.wait(std::chrono::seconds(1)); // must not throw; result_error is harmless and ignored
-    osl::MutexGuard g(theConfigLock()); // must not throw
+    osl::MutexGuard g(*lock_); // must not throw
     try {
         try {
             writeModFile(components_, url_, data_);
@@ -292,7 +294,7 @@ void Components::writeModifications() {
 void Components::flushModifications() {
     rtl::Reference< WriteThread > thread;
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         thread = writeThread_;
     }
     if (thread.is()) {
@@ -459,6 +461,7 @@ Components::Components(
     modificationTarget_(ModificationTarget::None)
 {
     assert(context.is());
+    lock_ = lock();
     OUString conf(expand("${CONFIGURATION_LAYERS}"));
     int layer = 0;
     for (sal_Int32 i = 0;;) {
@@ -619,7 +622,7 @@ Components::~Components()
     if (bExitWasCalled)
     {
         // do not write, re-join threads
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
 
         if (writeThread_.is())
         {
diff --git a/configmgr/source/components.hxx b/configmgr/source/components.hxx
index c23beee82777..bd4aeb5a78ac 100644
--- a/configmgr/source/components.hxx
+++ b/configmgr/source/components.hxx
@@ -161,6 +161,7 @@ private:
     int userExtensionLayer_;
     ModificationTarget modificationTarget_;
     OUString modificationFileUrl_;
+    std::shared_ptr<osl::Mutex> lock_;
 };
 
 }
diff --git a/configmgr/source/configurationprovider.cxx b/configmgr/source/configurationprovider.cxx
index 7d39593ab62e..ca8404a0c886 100644
--- a/configmgr/source/configurationprovider.cxx
+++ b/configmgr/source/configurationprovider.cxx
@@ -88,7 +88,8 @@ class Service:
 public:
     explicit Service(
         const css::uno::Reference< css::uno::XComponentContext >& context):
-        ServiceBase(m_aMutex), context_(context), default_(true)
+        ServiceBase(m_aMutex), context_(context), default_(true),
+        lock_( lock() )
     {
         assert(context.is());
     }
@@ -97,7 +98,8 @@ public:
         const css::uno::Reference< css::uno::XComponentContext >& context,
         OUString const & locale):
         ServiceBase(m_aMutex), context_(context), locale_(locale),
-        default_(false)
+        default_(false),
+        lock_( lock() )
     {
         assert(context.is());
     }
@@ -164,6 +166,7 @@ private:
     css::uno::Reference< css::uno::XComponentContext > context_;
     OUString locale_;
     bool default_;
+    std::shared_ptr<osl::Mutex> lock_;
 };
 
 css::uno::Reference< css::uno::XInterface > Service::createInstance(
@@ -249,7 +252,7 @@ Service::createInstanceWithArguments(
              " service " + ServiceSpecifier),
             static_cast< cppu::OWeakObject * >(this));
     }
-    osl::MutexGuard guard(theConfigLock());
+    osl::MutexGuard guard(*lock_);
     Components & components = Components::getSingleton(context_);
     rtl::Reference root(
         new RootAccess(components, nodepath, locale, update));
@@ -320,12 +323,12 @@ void Service::removeFlushListener(
 
 void Service::setLocale(css::lang::Locale const & eLocale)
 {
-    osl::MutexGuard guard(theConfigLock());
+    osl::MutexGuard guard(*lock_);
     locale_ = LanguageTag::convertToBcp47( eLocale, false);
 }
 
 css::lang::Locale Service::getLocale() {
-    osl::MutexGuard guard(theConfigLock());
+    osl::MutexGuard guard(*lock_);
     css::lang::Locale loc;
     if (! locale_.isEmpty()) {
         loc = LanguageTag::convertToLocale( locale_, false);
@@ -336,7 +339,7 @@ css::lang::Locale Service::getLocale() {
 void Service::flushModifications() const {
     Components * components;
     {
-        osl::MutexGuard guard(theConfigLock());
+        osl::MutexGuard guard(*lock_);
         components = &Components::getSingleton(context_);
     }
     components->flushModifications();
diff --git a/configmgr/source/defaultprovider.cxx b/configmgr/source/defaultprovider.cxx
index d07aad8424c3..c456954bb332 100644
--- a/configmgr/source/defaultprovider.cxx
+++ b/configmgr/source/defaultprovider.cxx
@@ -34,7 +34,7 @@ namespace configmgr { namespace default_provider {
 css::uno::Reference< css::uno::XInterface > create(
     css::uno::Reference< css::uno::XComponentContext > const & context)
 {
-    osl::MutexGuard guard(theConfigLock());
+    osl::MutexGuard guard(*lock());
     static css::uno::Reference< css::uno::XInterface > singleton(
         configuration_provider::createDefault(context));
     return singleton;
diff --git a/configmgr/source/lock.cxx b/configmgr/source/lock.cxx
index 7a30e409b8fa..3c0e25d432c5 100644
--- a/configmgr/source/lock.cxx
+++ b/configmgr/source/lock.cxx
@@ -19,15 +19,17 @@
 
 #include <sal/config.h>
 
+#include <osl/mutex.hxx>
+
 #include "lock.hxx"
 
 namespace configmgr {
 
-    osl::Mutex& theConfigLock()
-    {
-        static osl::Mutex lock;
-        return lock;
-    }
+std::shared_ptr<osl::Mutex> const & lock()
+{
+    static std::shared_ptr<osl::Mutex> theLock(new osl::Mutex);
+    return theLock;
+}
 
 }
 
diff --git a/configmgr/source/lock.hxx b/configmgr/source/lock.hxx
index 155c61e6f7fa..ee98efcc365f 100644
--- a/configmgr/source/lock.hxx
+++ b/configmgr/source/lock.hxx
@@ -22,10 +22,11 @@
 
 #include <sal/config.h>
 #include <osl/mutex.hxx>
+#include <memory>
 
 namespace configmgr {
 
-    osl::Mutex& theConfigLock();
+std::shared_ptr<osl::Mutex> const & lock();
 
 }
 
diff --git a/configmgr/source/readonlyaccess.cxx b/configmgr/source/readonlyaccess.cxx
index f8ee113eadf2..079459dc747f 100644
--- a/configmgr/source/readonlyaccess.cxx
+++ b/configmgr/source/readonlyaccess.cxx
@@ -93,7 +93,7 @@ void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
         throw css::uno::RuntimeException(
             "already initialized", static_cast< cppu::OWeakObject * >(this));
     }
-    osl::MutexGuard g2(theConfigLock());
+    osl::MutexGuard g2(*lock());
     Components & components = Components::getSingleton(context_);
     root_ = new RootAccess(components, "/", locale, false);
     components.addRootAccess(root_);
diff --git a/configmgr/source/readwriteaccess.cxx b/configmgr/source/readwriteaccess.cxx
index 57b1612ac89b..3cbf006c8ad4 100644
--- a/configmgr/source/readwriteaccess.cxx
+++ b/configmgr/source/readwriteaccess.cxx
@@ -115,7 +115,7 @@ void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
         throw css::uno::RuntimeException(
             "already initialized", static_cast< cppu::OWeakObject * >(this));
     }
-    osl::MutexGuard g2(theConfigLock());
+    osl::MutexGuard g2(*lock());
     Components & components = Components::getSingleton(context_);
     root_ = new RootAccess(components, "/", locale, true);
     components.addRootAccess(root_);
diff --git a/configmgr/source/rootaccess.cxx b/configmgr/source/rootaccess.cxx
index f3ab2eed49e4..17c9f111a27a 100644
--- a/configmgr/source/rootaccess.cxx
+++ b/configmgr/source/rootaccess.cxx
@@ -58,6 +58,7 @@ RootAccess::RootAccess(
     OUString const & locale, bool update):
     Access(components), pathRepresentation_(pathRepresentation),
     locale_(locale),
+    lock_( lock() ),
     update_(update), finalized_(false), alive_(true)
 {
 }
@@ -111,7 +112,7 @@ void RootAccess::addChangesListener(
 {
     assert(thisIs(IS_ANY));
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         if (!aListener.is()) {
             throw css::uno::RuntimeException(
@@ -132,7 +133,7 @@ void RootAccess::removeChangesListener(
     css::uno::Reference< css::util::XChangesListener > const & aListener)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     ChangesListeners::iterator i(changesListeners_.find(aListener));
     if (i != changesListeners_.end()) {
@@ -149,7 +150,7 @@ void RootAccess::commitChanges()
     }
     Broadcaster bc;
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
 
         checkLocalizedPropertyAccess();
         int finalizedLayer;
@@ -168,7 +169,7 @@ void RootAccess::commitChanges()
 
 sal_Bool RootAccess::hasPendingChanges() {
     assert(thisIs(IS_UPDATE));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     //TODO: Optimize:
     std::vector< css::util::ElementChange > changes;
@@ -179,7 +180,7 @@ sal_Bool RootAccess::hasPendingChanges() {
 css::uno::Sequence< ::css::util::ElementChange > RootAccess::getPendingChanges()
 {
     assert(thisIs(IS_UPDATE));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     std::vector< css::util::ElementChange > changes;
     reportChildChanges(&changes);
@@ -188,7 +189,7 @@ css::uno::Sequence< ::css::util::ElementChange > RootAccess::getPendingChanges()
 
 RootAccess::~RootAccess()
 {
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     if (alive_)
         getComponents().removeRootAccess(this);
 }
@@ -279,7 +280,7 @@ void RootAccess::clearListeners() throw() {
 css::uno::Any RootAccess::queryInterface(css::uno::Type const & aType)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     css::uno::Any res(Access::queryInterface(aType));
     if (res.hasValue()) {
@@ -300,7 +301,7 @@ css::uno::Any RootAccess::queryInterface(css::uno::Type const & aType)
 OUString RootAccess::getImplementationName()
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return "configmgr.RootAccess";
 }
diff --git a/configmgr/source/rootaccess.hxx b/configmgr/source/rootaccess.hxx
index bc26179fc2e2..0b2003f64f67 100644
--- a/configmgr/source/rootaccess.hxx
+++ b/configmgr/source/rootaccess.hxx
@@ -133,6 +133,8 @@ private:
     OUString name_;
     ChangesListeners changesListeners_;
 
+    std::shared_ptr<osl::Mutex> lock_;
+
     bool update_:1;
     bool finalized_:1;
     bool alive_:1;
diff --git a/configmgr/source/update.cxx b/configmgr/source/update.cxx
index c8f6505243ee..7529e21ef6f1 100644
--- a/configmgr/source/update.cxx
+++ b/configmgr/source/update.cxx
@@ -58,6 +58,7 @@ public:
         context_(context)
     {
         assert(context.is());
+        lock_ = lock();
     }
 
 private:
@@ -79,13 +80,14 @@ private:
         css::uno::Sequence< OUString > const & includedPaths,
         css::uno::Sequence< OUString > const & excludedPaths) override;
 
+    std::shared_ptr<osl::Mutex> lock_;
     css::uno::Reference< css::uno::XComponentContext > context_;
 };
 
 void Service::insertExtensionXcsFile(
     sal_Bool shared, OUString const & fileUri)
 {
-    osl::MutexGuard g(theConfigLock());
+    osl::MutexGuard g(*lock_);
     Components::getSingleton(context_).insertExtensionXcsFile(shared, fileUri);
 }
 
@@ -94,7 +96,7 @@ void Service::insertExtensionXcuFile(
 {
     Broadcaster bc;
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         Components & components = Components::getSingleton(context_);
         Modifications mods;
         components.insertExtensionXcuFile(shared, fileUri, &mods);
@@ -108,7 +110,7 @@ void Service::removeExtensionXcuFile(OUString const & fileUri)
 {
     Broadcaster bc;
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         Components & components = Components::getSingleton(context_);
         Modifications mods;
         components.removeExtensionXcuFile(fileUri, &mods);
@@ -125,7 +127,7 @@ void Service::insertModificationXcuFile(
 {
     Broadcaster bc;
     {
-        osl::MutexGuard g(theConfigLock());
+        osl::MutexGuard g(*lock_);
         Components & components = Components::getSingleton(context_);
         Modifications mods;
         components.insertModificationXcuFile(


More information about the Libreoffice-commits mailing list