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

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Thu Jul 22 19:17:49 UTC 2021


 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                  |    7 +-
 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, 103 insertions(+), 82 deletions(-)

New commits:
commit 55d47fd99c673ecb9830e9a60c55a3cc0d008b28
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Jul 22 11:58:35 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Jul 22 21:17:15 2021 +0200

    Revert "simplify locking in configmgr"
    
    This reverts commit 7f7dad7018c874542e0ab6a0fb0f05f21d112b53.
    
    And add some comments to the definition of the lock, to make
    it purpose obvious.
    
    Change-Id: Ib1a0b6345efab0febe9191341ce264c8d6070932
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119366
    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 ec4b1f36e084..02e3f557c684 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(configmgr::GetLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     std::vector< css::uno::Type > types { cppu::UnoType< css::uno::XInterface >::get(),
                                           cppu::UnoType< css::uno::XWeak >::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(configmgr::GetLock());
+    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(configmgr::GetLock());
+    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(configmgr::GetLock());
+    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(configmgr::GetLock());
+        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(configmgr::GetLock());
+        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(configmgr::GetLock());
+    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(configmgr::GetLock());
+    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(configmgr::GetLock());
+    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(configmgr::GetLock());
+    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(configmgr::GetLock());
+    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(configmgr::GetLock());
+    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(configmgr::GetLock());
+    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(configmgr::GetLock());
+    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(configmgr::GetLock());
+        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(configmgr::GetLock());
+        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(configmgr::GetLock());
+    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(configmgr::GetLock());
+    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(configmgr::GetLock());
+    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(configmgr::GetLock());
+    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(configmgr::GetLock());
+    osl::MutexGuard g(*lock_);
     return getChild(Name).is();
 }
 
 OUString Access::getHierarchicalName() {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(configmgr::GetLock());
+    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(configmgr::GetLock());
+    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(configmgr::GetLock());
+    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(configmgr::GetLock());
+        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(configmgr::GetLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return asProperty();
 }
@@ -698,7 +698,7 @@ void Access::setPropertyValue(
     assert(thisIs(IS_GROUP));
     Broadcaster bc;
     {
-        osl::MutexGuard g(configmgr::GetLock());
+        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(configmgr::GetLock());
+    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(configmgr::GetLock());
+        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(configmgr::GetLock());
+    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(configmgr::GetLock());
+        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(configmgr::GetLock());
+    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(configmgr::GetLock());
+        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(configmgr::GetLock());
+    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(configmgr::GetLock());
+        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(configmgr::GetLock());
+    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(configmgr::GetLock());
+        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(configmgr::GetLock());
+    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(configmgr::GetLock());
+        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(configmgr::GetLock());
+    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(configmgr::GetLock());
+    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(configmgr::GetLock());
+    osl::MutexGuard g(*lock_);
     return getSubChild(aHierarchicalName).is();
 }
 
@@ -1053,7 +1053,7 @@ void Access::replaceByName(
     assert(thisIs(IS_UPDATE));
     Broadcaster bc;
     {
-        osl::MutexGuard g(configmgr::GetLock());
+        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(configmgr::GetLock());
+        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(configmgr::GetLock());
+        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() )
 {
 }
 
@@ -2189,7 +2189,7 @@ rtl::Reference< Access > Access::getNotificationRoot() {
 
 #if !defined NDEBUG
 bool Access::thisIs(int what) {
-    osl::MutexGuard g(configmgr::GetLock());
+    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 d7cd90c11a6a..6d4ca787f3cc 100644
--- a/configmgr/source/access.hxx
+++ b/configmgr/source/access.hxx
@@ -434,6 +434,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 d8bc0a640857..41636b0e1bbe 100644
--- a/configmgr/source/childaccess.cxx
+++ b/configmgr/source/childaccess.cxx
@@ -66,7 +66,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());
 }
@@ -74,7 +75,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());
 }
@@ -142,7 +144,7 @@ void ChildAccess::release() noexcept {
 css::uno::Reference< css::uno::XInterface > ChildAccess::getParent()
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(configmgr::GetLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return static_cast< cppu::OWeakObject * >(parent_.get());
 }
@@ -150,7 +152,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(configmgr::GetLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     throw css::lang::NoSupportException(
         "setParent", static_cast< cppu::OWeakObject * >(this));
@@ -160,7 +162,7 @@ sal_Int64 ChildAccess::getSomething(
     css::uno::Sequence< sal_Int8 > const & aIdentifier)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(configmgr::GetLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return aIdentifier == getTunnelId()
         ? reinterpret_cast< sal_Int64 >(this) : 0;
@@ -308,7 +310,7 @@ void ChildAccess::commitChanges(bool valid, Modifications * globalModifications)
 }
 
 ChildAccess::~ChildAccess() {
-    osl::MutexGuard g(configmgr::GetLock());
+    osl::MutexGuard g(*lock_);
     if (parent_.is()) {
         parent_->releaseChild(name_);
     }
@@ -333,7 +335,7 @@ void ChildAccess::addSupportedServiceNames(
 css::uno::Any ChildAccess::queryInterface(css::uno::Type const & aType)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(configmgr::GetLock());
+    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 85d3b5bda4c7..2aecdf6757ea 100644
--- a/configmgr/source/childaccess.hxx
+++ b/configmgr/source/childaccess.hxx
@@ -128,6 +128,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 078de2cd3c3f..65bc00da9517 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(configmgr::GetLock()); // must not throw
+    osl::MutexGuard g(*lock_); // must not throw
     try {
         try {
             writeModFile(components_, url_, data_);
@@ -293,7 +295,7 @@ void Components::writeModifications() {
 void Components::flushModifications() {
     rtl::Reference< WriteThread > thread;
     {
-        osl::MutexGuard g(configmgr::GetLock());
+        osl::MutexGuard g(*lock_);
         thread = writeThread_;
     }
     if (thread.is()) {
@@ -461,6 +463,7 @@ Components::Components(
     modificationTarget_(ModificationTarget::None)
 {
     assert(context.is());
+    lock_ = lock();
     OUString conf(expand("${CONFIGURATION_LAYERS}"));
     int layer = 0;
     for (sal_Int32 i = 0;;) {
@@ -618,7 +621,7 @@ Components::~Components()
     if (bExitWasCalled)
     {
         // do not write, re-join threads
-        osl::MutexGuard g(configmgr::GetLock());
+        osl::MutexGuard g(*lock_);
 
         if (writeThread_.is())
         {
diff --git a/configmgr/source/components.hxx b/configmgr/source/components.hxx
index 036ab702d394..a44097810015 100644
--- a/configmgr/source/components.hxx
+++ b/configmgr/source/components.hxx
@@ -158,6 +158,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 bc9615432224..f9936b6ba1a3 100644
--- a/configmgr/source/configurationprovider.cxx
+++ b/configmgr/source/configurationprovider.cxx
@@ -85,7 +85,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());
     }
@@ -94,7 +95,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());
     }
@@ -161,6 +163,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(
@@ -246,7 +249,7 @@ Service::createInstanceWithArguments(
              " service " + ServiceSpecifier),
             static_cast< cppu::OWeakObject * >(this));
     }
-    osl::MutexGuard guard(configmgr::GetLock());
+    osl::MutexGuard guard(*lock_);
     Components & components = Components::getSingleton(context_);
     rtl::Reference root(
         new RootAccess(components, nodepath, locale, update));
@@ -314,12 +317,12 @@ void Service::removeFlushListener(
 
 void Service::setLocale(css::lang::Locale const & eLocale)
 {
-    osl::MutexGuard guard(configmgr::GetLock());
+    osl::MutexGuard guard(*lock_);
     locale_ = LanguageTag::convertToBcp47( eLocale, false);
 }
 
 css::lang::Locale Service::getLocale() {
-    osl::MutexGuard guard(configmgr::GetLock());
+    osl::MutexGuard guard(*lock_);
     css::lang::Locale loc;
     if (! locale_.isEmpty()) {
         loc = LanguageTag::convertToLocale( locale_, false);
@@ -330,7 +333,7 @@ css::lang::Locale Service::getLocale() {
 void Service::flushModifications() const {
     Components * components;
     {
-        osl::MutexGuard guard(configmgr::GetLock());
+        osl::MutexGuard guard(*lock_);
         components = &Components::getSingleton(context_);
     }
     components->flushModifications();
diff --git a/configmgr/source/defaultprovider.cxx b/configmgr/source/defaultprovider.cxx
index fe79c174f654..7161659e0fa6 100644
--- a/configmgr/source/defaultprovider.cxx
+++ b/configmgr/source/defaultprovider.cxx
@@ -33,7 +33,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
 com_sun_star_comp_configuration_DefaultProvider_get_implementation(
     css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
 {
-    osl::MutexGuard guard(configmgr::GetLock());
+    osl::MutexGuard guard(*configmgr::lock());
     css::uno::Reference<css::uno::XInterface> singleton(
         configmgr::configuration_provider::createDefault(context));
     singleton->acquire();
diff --git a/configmgr/source/lock.cxx b/configmgr/source/lock.cxx
index 33940fef91ed..65b490b78b26 100644
--- a/configmgr/source/lock.cxx
+++ b/configmgr/source/lock.cxx
@@ -25,9 +25,12 @@
 
 namespace configmgr
 {
-osl::Mutex& GetLock()
+std::shared_ptr<osl::Mutex> const& lock()
 {
-    static osl::Mutex theLock;
+    // fdo#31494# get ownership right
+    // Ensure that the mutex lives as long as all its consumers, otherwise
+    // the configmgr DLL exit delete this before unotools releases some configmgr derived reference.
+    static std::shared_ptr<osl::Mutex> theLock = std::make_shared<osl::Mutex>();
     return theLock;
 }
 }
diff --git a/configmgr/source/lock.hxx b/configmgr/source/lock.hxx
index 27353f8233a7..195dbf5e72c4 100644
--- a/configmgr/source/lock.hxx
+++ b/configmgr/source/lock.hxx
@@ -21,10 +21,11 @@
 
 #include <sal/config.h>
 #include <osl/mutex.hxx>
+#include <memory>
 
 namespace configmgr
 {
-osl::Mutex& GetLock();
+std::shared_ptr<osl::Mutex> const& lock();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/configmgr/source/readonlyaccess.cxx b/configmgr/source/readonlyaccess.cxx
index 76da9e5c71a9..286963c783a2 100644
--- a/configmgr/source/readonlyaccess.cxx
+++ b/configmgr/source/readonlyaccess.cxx
@@ -92,7 +92,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(configmgr::GetLock());
+    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 fc231923588e..292124ddec25 100644
--- a/configmgr/source/readwriteaccess.cxx
+++ b/configmgr/source/readwriteaccess.cxx
@@ -114,7 +114,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(configmgr::GetLock());
+    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 e24819ee8118..17c8f7ec12a2 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)
 {
 }
@@ -112,7 +113,7 @@ void RootAccess::addChangesListener(
 {
     assert(thisIs(IS_ANY));
     {
-        osl::MutexGuard g(configmgr::GetLock());
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         if (!aListener.is()) {
             throw css::uno::RuntimeException(
@@ -133,7 +134,7 @@ void RootAccess::removeChangesListener(
     css::uno::Reference< css::util::XChangesListener > const & aListener)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(configmgr::GetLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     ChangesListeners::iterator i(changesListeners_.find(aListener));
     if (i != changesListeners_.end()) {
@@ -150,7 +151,7 @@ void RootAccess::commitChanges()
     }
     Broadcaster bc;
     {
-        osl::MutexGuard g(configmgr::GetLock());
+        osl::MutexGuard g(*lock_);
 
         checkLocalizedPropertyAccess();
         int finalizedLayer;
@@ -169,7 +170,7 @@ void RootAccess::commitChanges()
 
 sal_Bool RootAccess::hasPendingChanges() {
     assert(thisIs(IS_UPDATE));
-    osl::MutexGuard g(configmgr::GetLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     //TODO: Optimize:
     std::vector< css::util::ElementChange > changes;
@@ -180,7 +181,7 @@ sal_Bool RootAccess::hasPendingChanges() {
 css::uno::Sequence< ::css::util::ElementChange > RootAccess::getPendingChanges()
 {
     assert(thisIs(IS_UPDATE));
-    osl::MutexGuard g(configmgr::GetLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     std::vector< css::util::ElementChange > changes;
     reportChildChanges(&changes);
@@ -189,7 +190,7 @@ css::uno::Sequence< ::css::util::ElementChange > RootAccess::getPendingChanges()
 
 RootAccess::~RootAccess()
 {
-    osl::MutexGuard g(configmgr::GetLock());
+    osl::MutexGuard g(*lock_);
     if (alive_)
         getComponents().removeRootAccess(this);
 }
@@ -280,7 +281,7 @@ void RootAccess::clearListeners() noexcept {
 css::uno::Any RootAccess::queryInterface(css::uno::Type const & aType)
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(configmgr::GetLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     css::uno::Any res(Access::queryInterface(aType));
     if (res.hasValue()) {
@@ -301,7 +302,7 @@ css::uno::Any RootAccess::queryInterface(css::uno::Type const & aType)
 OUString RootAccess::getImplementationName()
 {
     assert(thisIs(IS_ANY));
-    osl::MutexGuard g(configmgr::GetLock());
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return "configmgr.RootAccess";
 }
diff --git a/configmgr/source/rootaccess.hxx b/configmgr/source/rootaccess.hxx
index 2e71d0943e7b..11fbea450eed 100644
--- a/configmgr/source/rootaccess.hxx
+++ b/configmgr/source/rootaccess.hxx
@@ -132,6 +132,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 02b4dd5309fc..1cc2a06fe2a2 100644
--- a/configmgr/source/update.cxx
+++ b/configmgr/source/update.cxx
@@ -57,6 +57,7 @@ public:
         context_(context)
     {
         assert(context.is());
+        lock_ = lock();
     }
 
 private:
@@ -78,13 +79,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(configmgr::GetLock());
+    osl::MutexGuard g(*lock_);
     Components::getSingleton(context_).insertExtensionXcsFile(shared, fileUri);
 }
 
@@ -93,7 +95,7 @@ void Service::insertExtensionXcuFile(
 {
     Broadcaster bc;
     {
-        osl::MutexGuard g(configmgr::GetLock());
+        osl::MutexGuard g(*lock_);
         Components & components = Components::getSingleton(context_);
         Modifications mods;
         components.insertExtensionXcuFile(shared, fileUri, &mods);
@@ -107,7 +109,7 @@ void Service::removeExtensionXcuFile(OUString const & fileUri)
 {
     Broadcaster bc;
     {
-        osl::MutexGuard g(configmgr::GetLock());
+        osl::MutexGuard g(*lock_);
         Components & components = Components::getSingleton(context_);
         Modifications mods;
         components.removeExtensionXcuFile(fileUri, &mods);
@@ -124,7 +126,7 @@ void Service::insertModificationXcuFile(
 {
     Broadcaster bc;
     {
-        osl::MutexGuard g(configmgr::GetLock());
+        osl::MutexGuard g(*lock_);
         Components & components = Components::getSingleton(context_);
         Modifications mods;
         components.insertModificationXcuFile(


More information about the Libreoffice-commits mailing list