[Libreoffice-commits] .: Branch 'libreoffice-3-3' - configmgr/source

Caolán McNamara caolan at kemper.freedesktop.org
Thu Nov 25 12:42:42 PST 2010


 configmgr/source/access.cxx                |   96 ++++++++++++++---------------
 configmgr/source/access.hxx                |    3 
 configmgr/source/childaccess.cxx           |   12 ++-
 configmgr/source/childaccess.hxx           |    2 
 configmgr/source/components.cxx            |   18 ++++-
 configmgr/source/components.hxx            |    4 +
 configmgr/source/configurationprovider.cxx |   10 +--
 configmgr/source/defaultprovider.cxx       |   10 ++-
 configmgr/source/lock.cxx                  |    8 ++
 configmgr/source/lock.hxx                  |    4 -
 configmgr/source/rootaccess.cxx            |   18 +++--
 configmgr/source/rootaccess.hxx            |    3 
 configmgr/source/update.cxx                |   16 +++-
 13 files changed, 128 insertions(+), 76 deletions(-)

New commits:
commit f10c27040a40cbc9e0b97258c1a0edc5f721d37f
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Thu Nov 25 20:36:03 2010 +0000

    Resolves: fdo#31494# get ownership right
    
    Ensure that the mutex lives as long as all its consumers. And
    avoid launching threads if they have no work to do.
    (cherry picked from commit e34373935bff7f1ed8e8bfd06b54383917b1177a)

diff --git a/configmgr/source/access.cxx b/configmgr/source/access.cxx
index fda967a..0382054 100644
--- a/configmgr/source/access.cxx
+++ b/configmgr/source/access.cxx
@@ -166,7 +166,9 @@ void Access::initBroadcaster(
 
 Access::Access(Components & components):
     components_(components), disposed_(false)
-{}
+{
+    lock_ = lock();
+}
 
 Access::~Access() {}
 
@@ -851,7 +853,7 @@ css::uno::Sequence< css::uno::Type > Access::getTypes()
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     comphelper::SequenceAsVector< css::uno::Type > types;
     types.push_back(cppu::UnoType< css::uno::XInterface >::get());
@@ -900,7 +902,7 @@ css::uno::Sequence< sal_Int8 > Access::getImplementationId()
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return css::uno::Sequence< sal_Int8 >();
 }
@@ -908,7 +910,7 @@ css::uno::Sequence< sal_Int8 > Access::getImplementationId()
 rtl::OUString Access::getImplementationName() throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     throw css::uno::RuntimeException(
         rtl::OUString(
@@ -921,7 +923,7 @@ sal_Bool Access::supportsService(rtl::OUString const & ServiceName)
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     css::uno::Sequence< rtl::OUString > names(getSupportedServiceNames());
     for (sal_Int32 i = 0; i < names.getLength(); ++i) {
@@ -936,7 +938,7 @@ css::uno::Sequence< rtl::OUString > Access::getSupportedServiceNames()
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     comphelper::SequenceAsVector< rtl::OUString > services;
     services.push_back(
@@ -1000,7 +1002,7 @@ void Access::dispose() throw (css::uno::RuntimeException) {
     OSL_ASSERT(thisIs(IS_ANY));
     Broadcaster bc;
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         if (getParentAccess().is()) {
             throw css::uno::RuntimeException(
@@ -1025,7 +1027,7 @@ void Access::addEventListener(
 {
     OSL_ASSERT(thisIs(IS_ANY));
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         if (!xListener.is()) {
             throw css::uno::RuntimeException(
@@ -1048,7 +1050,7 @@ void Access::removeEventListener(
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     DisposeListeners::iterator i(disposeListeners_.find(aListener));
     if (i != disposeListeners_.end()) {
@@ -1058,7 +1060,7 @@ void Access::removeEventListener(
 
 css::uno::Type Access::getElementType() throw (css::uno::RuntimeException) {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     rtl::Reference< Node > p(getNode());
     switch (p->kind()) {
@@ -1082,7 +1084,7 @@ css::uno::Type Access::getElementType() throw (css::uno::RuntimeException) {
 
 sal_Bool Access::hasElements() throw (css::uno::RuntimeException) {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return !getAllChildren().empty(); //TODO: optimize
 }
@@ -1093,7 +1095,7 @@ css::uno::Any Access::getByName(rtl::OUString const & aName)
         css::lang::WrappedTargetException, css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     rtl::Reference< ChildAccess > child(getChild(aName));
     if (!child.is()) {
@@ -1107,7 +1109,7 @@ css::uno::Sequence< rtl::OUString > Access::getElementNames()
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     std::vector< rtl::Reference< ChildAccess > > children(getAllChildren());
     comphelper::SequenceAsVector< rtl::OUString > names;
@@ -1124,7 +1126,7 @@ sal_Bool Access::hasByName(rtl::OUString const & aName)
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return getChild(aName).is();
 }
@@ -1133,7 +1135,7 @@ css::uno::Any Access::getByHierarchicalName(rtl::OUString const & aName)
     throw (css::container::NoSuchElementException, css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     rtl::Reference< ChildAccess > child(getSubChild(aName));
     if (!child.is()) {
@@ -1147,7 +1149,7 @@ sal_Bool Access::hasByHierarchicalName(rtl::OUString const & aName)
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return getSubChild(aName).is();
 }
@@ -1158,7 +1160,7 @@ void Access::addContainerListener(
 {
     OSL_ASSERT(thisIs(IS_ANY));
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         if (!xListener.is()) {
             throw css::uno::RuntimeException(
@@ -1181,7 +1183,7 @@ void Access::removeContainerListener(
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     ContainerListeners::iterator i(containerListeners_.find(xListener));
     if (i != containerListeners_.end()) {
@@ -1193,7 +1195,7 @@ rtl::OUString Access::getExactName(rtl::OUString const & aApproximateName)
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return aApproximateName;
 }
@@ -1202,7 +1204,7 @@ css::uno::Sequence< css::beans::Property > Access::getProperties()
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_GROUP));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     std::vector< rtl::Reference< ChildAccess > > children(getAllChildren());
     comphelper::SequenceAsVector< css::beans::Property > properties;
     for (std::vector< rtl::Reference< ChildAccess > >::iterator i(
@@ -1218,7 +1220,7 @@ css::beans::Property Access::getPropertyByName(rtl::OUString const & aName)
     throw (css::beans::UnknownPropertyException, css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_GROUP));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     rtl::Reference< ChildAccess > child(getChild(aName));
     if (!child.is()) {
         throw css::beans::UnknownPropertyException(
@@ -1231,13 +1233,13 @@ sal_Bool Access::hasPropertyByName(rtl::OUString const & Name)
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_GROUP));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     return getChild(Name).is();
 }
 
 rtl::OUString Access::getHierarchicalName() throw (css::uno::RuntimeException) {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     // For backwards compatibility, return an absolute path representation where
     // available:
@@ -1261,7 +1263,7 @@ rtl::OUString Access::composeHierarchicalName(
         css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     if (aRelativeName.getLength() == 0 || aRelativeName[0] == '/') {
         throw css::lang::IllegalArgumentException(
@@ -1281,7 +1283,7 @@ rtl::OUString Access::composeHierarchicalName(
 
 rtl::OUString Access::getName() throw (css::uno::RuntimeException) {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return getNameInternal();
 }
@@ -1292,7 +1294,7 @@ void Access::setName(rtl::OUString const & aName)
     OSL_ASSERT(thisIs(IS_ANY));
     Broadcaster bc;
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         checkFinalized();
         Modifications localMods;
@@ -1356,7 +1358,7 @@ void Access::setName(rtl::OUString const & aName)
 css::beans::Property Access::getAsProperty() throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return asProperty();
 }
@@ -1378,7 +1380,7 @@ void Access::setPropertyValue(
     OSL_ASSERT(thisIs(IS_GROUP));
     Broadcaster bc;
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         if (!getRootAccess()->isUpdate()) {
             throw css::uno::RuntimeException(
                 rtl::OUString(
@@ -1402,7 +1404,7 @@ css::uno::Any Access::getPropertyValue(rtl::OUString const & PropertyName)
         css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_GROUP));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     rtl::Reference< ChildAccess > child(getChild(PropertyName));
     if (!child.is()) {
         throw css::beans::UnknownPropertyException(
@@ -1421,7 +1423,7 @@ void Access::addPropertyChangeListener(
 {
     OSL_ASSERT(thisIs(IS_GROUP));
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         if (!xListener.is()) {
             throw css::uno::RuntimeException(
                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("null listener")),
@@ -1448,7 +1450,7 @@ void Access::removePropertyChangeListener(
         css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_GROUP));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkKnownProperty(aPropertyName);
     PropertyChangeListeners::iterator i(
         propertyChangeListeners_.find(aPropertyName));
@@ -1473,7 +1475,7 @@ void Access::addVetoableChangeListener(
 {
     OSL_ASSERT(thisIs(IS_GROUP));
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         if (!aListener.is()) {
             throw css::uno::RuntimeException(
                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("null listener")),
@@ -1501,7 +1503,7 @@ void Access::removeVetoableChangeListener(
         css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_GROUP));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkKnownProperty(PropertyName);
     VetoableChangeListeners::iterator i(
         vetoableChangeListeners_.find(PropertyName));
@@ -1526,7 +1528,7 @@ void Access::setPropertyValues(
     OSL_ASSERT(thisIs(IS_GROUP));
     Broadcaster bc;
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         if (!getRootAccess()->isUpdate()) {
             throw css::uno::RuntimeException(
                 rtl::OUString(
@@ -1563,7 +1565,7 @@ css::uno::Sequence< css::uno::Any > Access::getPropertyValues(
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_GROUP));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     css::uno::Sequence< css::uno::Any > vals(aPropertyNames.getLength());
     for (sal_Int32 i = 0; i < aPropertyNames.getLength(); ++i) {
         rtl::Reference< ChildAccess > child(getChild(aPropertyNames[i]));
@@ -1588,7 +1590,7 @@ void Access::addPropertiesChangeListener(
 {
     OSL_ASSERT(thisIs(IS_GROUP));
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         if (!xListener.is()) {
             throw css::uno::RuntimeException(
                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("null listener")),
@@ -1611,7 +1613,7 @@ void Access::removePropertiesChangeListener(
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_GROUP));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     PropertiesChangeListeners::iterator i(
         propertiesChangeListeners_.find(xListener));
     if (i != propertiesChangeListeners_.end()) {
@@ -1654,7 +1656,7 @@ void Access::setHierarchicalPropertyValue(
     OSL_ASSERT(thisIs(IS_GROUP));
     Broadcaster bc;
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         if (!getRootAccess()->isUpdate()) {
             throw css::uno::RuntimeException(
                 rtl::OUString(
@@ -1686,7 +1688,7 @@ css::uno::Any Access::getHierarchicalPropertyValue(
         css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_GROUP));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     rtl::Reference< ChildAccess > child(getSubChild(aHierarchicalPropertyName));
     if (!child.is()) {
         throw css::beans::UnknownPropertyException(
@@ -1706,7 +1708,7 @@ void Access::setHierarchicalPropertyValues(
     OSL_ASSERT(thisIs(IS_GROUP));
     Broadcaster bc;
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         if (!getRootAccess()->isUpdate()) {
             throw css::uno::RuntimeException(
                 rtl::OUString(
@@ -1750,7 +1752,7 @@ css::uno::Sequence< css::uno::Any > Access::getHierarchicalPropertyValues(
         css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_GROUP));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     css::uno::Sequence< css::uno::Any > vals(
         aHierarchicalPropertyNames.getLength());
     for (sal_Int32 i = 0; i < aHierarchicalPropertyNames.getLength(); ++i) {
@@ -1774,7 +1776,7 @@ css::beans::Property Access::getPropertyByHierarchicalName(
     throw (css::beans::UnknownPropertyException, css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_GROUP));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     rtl::Reference< ChildAccess > child(getSubChild(aHierarchicalName));
     if (!child.is()) {
         throw css::beans::UnknownPropertyException(
@@ -1788,7 +1790,7 @@ sal_Bool Access::hasPropertyByHierarchicalName(
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_GROUP));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     return getSubChild(aHierarchicalName).is();
 }
 
@@ -1802,7 +1804,7 @@ void Access::replaceByName(
     OSL_ASSERT(thisIs(IS_UPDATE));
     Broadcaster bc;
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         rtl::Reference< ChildAccess > child(getChild(aName));
         if (!child.is()) {
@@ -1846,7 +1848,7 @@ void Access::insertByName(
     OSL_ASSERT(thisIs(IS_EXTENSIBLE|IS_UPDATE));
     Broadcaster bc;
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         checkFinalized();
         if (getChild(aName).is()) {
@@ -1896,7 +1898,7 @@ void Access::removeByName(rtl::OUString const & aName)
     OSL_ASSERT(thisIs(IS_EXTENSIBLE|IS_UPDATE));
     Broadcaster bc;
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         rtl::Reference< ChildAccess > child(getChild(aName));
         if (!child.is() || child->isFinalized() ||
@@ -2189,7 +2191,7 @@ rtl::Reference< Access > Access::getNotificationRoot() {
 
 #if OSL_DEBUG_LEVEL > 0
 bool Access::thisIs(int what) {
-    osl::MutexGuard g(lock);
+    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 32c0ea9..8a05329 100644
--- a/configmgr/source/access.hxx
+++ b/configmgr/source/access.hxx
@@ -36,6 +36,7 @@
 #include <vector>
 
 #include "boost/noncopyable.hpp"
+#include "boost/shared_ptr.hpp"
 #include "com/sun/star/beans/PropertyVetoException.hpp"
 #include "com/sun/star/beans/UnknownPropertyException.hpp"
 #include "com/sun/star/beans/XExactName.hpp"
@@ -569,6 +570,8 @@ private:
     PropertiesChangeListeners propertiesChangeListeners_;
     bool disposed_;
 
+    boost::shared_ptr<osl::Mutex> lock_;
+
 #if OSL_DEBUG_LEVEL > 0
 protected:
     enum {
diff --git a/configmgr/source/childaccess.cxx b/configmgr/source/childaccess.cxx
index 3ec23b7..3d9c40b 100644
--- a/configmgr/source/childaccess.cxx
+++ b/configmgr/source/childaccess.cxx
@@ -95,6 +95,7 @@ ChildAccess::ChildAccess(
     Access(components), root_(root), parent_(parent), name_(name), node_(node),
     inTransaction_(false)
 {
+    lock_ = lock();
     OSL_ASSERT(root.is() && parent.is() && node.is());
 }
 
@@ -103,6 +104,7 @@ ChildAccess::ChildAccess(
     rtl::Reference< Node > const & node):
     Access(components), root_(root), node_(node), inTransaction_(false)
 {
+    lock_ = lock();
     OSL_ASSERT(root.is() && node.is());
 }
 
@@ -169,7 +171,7 @@ css::uno::Reference< css::uno::XInterface > ChildAccess::getParent()
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return static_cast< cppu::OWeakObject * >(parent_.get());
 }
@@ -178,7 +180,7 @@ void ChildAccess::setParent(css::uno::Reference< css::uno::XInterface > const &)
     throw (css::lang::NoSupportException, css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     throw css::lang::NoSupportException(
         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("setParent")),
@@ -190,7 +192,7 @@ sal_Int64 ChildAccess::getSomething(
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     return aIdentifier == getTunnelId()
         ? reinterpret_cast< sal_Int64 >(this) : 0;
@@ -360,7 +362,7 @@ void ChildAccess::commitChanges(bool valid, Modifications * globalModifications)
 }
 
 ChildAccess::~ChildAccess() {
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     if (parent_.is()) {
         parent_->releaseChild(name_);
     }
@@ -390,7 +392,7 @@ css::uno::Any ChildAccess::queryInterface(css::uno::Type const & aType)
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    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 3d9b2fc..977d97e 100644
--- a/configmgr/source/childaccess.hxx
+++ b/configmgr/source/childaccess.hxx
@@ -40,6 +40,7 @@
 #include "com/sun/star/uno/Reference.hxx"
 #include "com/sun/star/uno/RuntimeException.hpp"
 #include "com/sun/star/uno/Sequence.hxx"
+#include "boost/shared_ptr.hpp"
 #include "rtl/ref.hxx"
 #include "sal/types.h"
 
@@ -151,6 +152,7 @@ private:
     std::auto_ptr< com::sun::star::uno::Any > changedValue_;
     bool inTransaction_;
         // to determine if a free node can be inserted underneath some root
+    boost::shared_ptr<osl::Mutex> lock_;
 };
 
 }
diff --git a/configmgr/source/components.cxx b/configmgr/source/components.cxx
index 2e07320..e6cfb10 100644
--- a/configmgr/source/components.cxx
+++ b/configmgr/source/components.cxx
@@ -183,6 +183,7 @@ private:
     rtl::OUString url_;
     Data const & data_;
     osl::Condition delay_;
+    boost::shared_ptr<osl::Mutex> lock_;
 };
 
 Components::WriteThread::WriteThread(
@@ -190,6 +191,7 @@ Components::WriteThread::WriteThread(
     rtl::OUString const & url, Data const & data):
     reference_(reference), components_(components), url_(url), data_(data)
 {
+    lock_ = lock();
     OSL_ASSERT(reference != 0);
     acquire();
 }
@@ -197,7 +199,7 @@ Components::WriteThread::WriteThread(
 void Components::WriteThread::run() {
     TimeValue t = { 1, 0 }; // 1 sec
     delay_.wait(&t); // must not throw; result_error is harmless and ignored
-    osl::MutexGuard g(lock); // must not throw
+    osl::MutexGuard g(*lock_); // must not throw
     try {
         try {
             writeModFile(components_, url_, data_);
@@ -304,7 +306,17 @@ void Components::addModification(Path const & path) {
     data_.modifications.add(path);
 }
 
+bool Components::hasModifications() const
+{
+    return data_.modifications.getRoot().children.begin() !=
+        data_.modifications.getRoot().children.end();
+}
+
 void Components::writeModifications() {
+
+    if (!hasModifications())
+        return;
+
     if (!writeThread_.is()) {
         writeThread_ = new WriteThread(
             &writeThread_, *this, getModificationFileUrl(), data_);
@@ -315,7 +327,7 @@ void Components::writeModifications() {
 void Components::flushModifications() {
     rtl::Reference< WriteThread > thread;
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         thread = writeThread_;
     }
     if (thread.is()) {
@@ -506,6 +518,8 @@ Components::Components(
     css::uno::Reference< css::uno::XComponentContext > const & context):
     context_(context)
 {
+    lock_ = lock();
+
     OSL_ASSERT(context.is());
     RTL_LOGFILE_TRACE_AUTHOR("configmgr", "sb", "begin parsing");
     parseXcsXcuLayer(
diff --git a/configmgr/source/components.hxx b/configmgr/source/components.hxx
index 2d0843b..e810c6a 100644
--- a/configmgr/source/components.hxx
+++ b/configmgr/source/components.hxx
@@ -35,6 +35,7 @@
 #include <set>
 
 #include "boost/noncopyable.hpp"
+#include "boost/shared_ptr.hpp"
 #include "com/sun/star/beans/Optional.hpp"
 #include "com/sun/star/uno/Reference.hxx"
 #include "rtl/ref.hxx"
@@ -95,6 +96,8 @@ public:
 
     void writeModifications();
 
+    bool hasModifications() const;
+
     void flushModifications();
         // must be called with configmgr::lock unaquired; must be called before
         // shutdown if writeModifications has ever been called (probably
@@ -174,6 +177,7 @@ private:
     WeakRootSet roots_;
     ExternalServices externalServices_;
     rtl::Reference< WriteThread > writeThread_;
+    boost::shared_ptr<osl::Mutex> lock_;
 };
 
 }
diff --git a/configmgr/source/configurationprovider.cxx b/configmgr/source/configurationprovider.cxx
index ed50642..cccb746 100644
--- a/configmgr/source/configurationprovider.cxx
+++ b/configmgr/source/configurationprovider.cxx
@@ -109,6 +109,7 @@ public:
         ServiceBase(*static_cast< osl::Mutex * >(this)), context_(context),
         locale_(locale)
     {
+        lock_ = lock();
         OSL_ASSERT(context.is());
     }
 
@@ -173,6 +174,7 @@ private:
 
     css::uno::Reference< css::uno::XComponentContext > context_;
     rtl::OUString locale_;
+    boost::shared_ptr<osl::Mutex> lock_;
 };
 
 css::uno::Reference< css::uno::XInterface > Service::createInstance(
@@ -276,7 +278,7 @@ Service::createInstanceWithArguments(
              ServiceSpecifier),
             static_cast< cppu::OWeakObject * >(this));
     }
-    osl::MutexGuard guard(lock);
+    osl::MutexGuard guard(*lock_);
     Components::initSingleton(context_);
     Components & components = Components::getSingleton();
     rtl::Reference< RootAccess > root(
@@ -358,13 +360,13 @@ void Service::removeFlushListener(
 void Service::setLocale(css::lang::Locale const & eLocale)
     throw (css::uno::RuntimeException)
 {
-    osl::MutexGuard guard(lock);
+    osl::MutexGuard guard(*lock_);
     locale_ = comphelper::Locale(
         eLocale.Language, eLocale.Country, eLocale.Variant).toISO();
 }
 
 css::lang::Locale Service::getLocale() throw (css::uno::RuntimeException) {
-    osl::MutexGuard guard(lock);
+    osl::MutexGuard guard(*lock_);
     css::lang::Locale loc;
     if (locale_.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("*"))) {
         loc.Language = locale_;
@@ -388,7 +390,7 @@ css::lang::Locale Service::getLocale() throw (css::uno::RuntimeException) {
 void Service::flushModifications() const {
     Components * components;
     {
-        osl::MutexGuard guard(lock);
+        osl::MutexGuard guard(*lock_);
         Components::initSingleton(context_);
         components = &Components::getSingleton();
     }
diff --git a/configmgr/source/defaultprovider.cxx b/configmgr/source/defaultprovider.cxx
index aa928d7..16cf66d 100644
--- a/configmgr/source/defaultprovider.cxx
+++ b/configmgr/source/defaultprovider.cxx
@@ -30,6 +30,7 @@
 #include "sal/config.h"
 
 #include "boost/noncopyable.hpp"
+#include "boost/shared_ptr.hpp"
 #include "com/sun/star/lang/XSingleComponentFactory.hpp"
 #include "com/sun/star/uno/Any.hxx"
 #include "com/sun/star/uno/Exception.hpp"
@@ -60,7 +61,10 @@ class Factory:
     private boost::noncopyable
 {
 public:
-    Factory() {}
+    Factory()
+    {
+        lock_ = lock();
+    }
 
 private:
     virtual ~Factory() {}
@@ -75,6 +79,8 @@ private:
         css::uno::Sequence< css::uno::Any > const & Arguments,
         css::uno::Reference< css::uno::XComponentContext > const & Context)
         throw (css::uno::Exception, css::uno::RuntimeException);
+
+    boost::shared_ptr<osl::Mutex> lock_;
 };
 
 css::uno::Reference< css::uno::XInterface > Factory::createInstanceWithContext(
@@ -99,7 +105,7 @@ Factory::createInstanceWithArgumentsAndContext(
                     " instantiated without arguments")),
             static_cast< cppu::OWeakObject * >(this));
     }
-    osl::MutexGuard guard(lock);
+    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 4894ab2..3950a2d 100644
--- a/configmgr/source/lock.cxx
+++ b/configmgr/source/lock.cxx
@@ -35,7 +35,13 @@
 
 namespace configmgr {
 
-osl::Mutex lock;
+boost::shared_ptr<osl::Mutex> lock()
+{
+    static boost::shared_ptr<osl::Mutex> theLock;
+    if (!theLock.get())
+        theLock.reset(new osl::Mutex);
+    return theLock;
+}
 
 }
 
diff --git a/configmgr/source/lock.hxx b/configmgr/source/lock.hxx
index 8b3c7b4..b37e83a 100644
--- a/configmgr/source/lock.hxx
+++ b/configmgr/source/lock.hxx
@@ -30,12 +30,12 @@
 #define INCLUDED_CONFIGMGR_SOURCE_LOCK_HXX
 
 #include "sal/config.h"
-
 #include "osl/mutex.hxx"
+#include "boost/shared_ptr.hpp"
 
 namespace configmgr {
 
-extern osl::Mutex lock;
+boost::shared_ptr<osl::Mutex> lock();
 
 }
 
diff --git a/configmgr/source/rootaccess.cxx b/configmgr/source/rootaccess.cxx
index 72716aa..27f3884 100644
--- a/configmgr/source/rootaccess.cxx
+++ b/configmgr/source/rootaccess.cxx
@@ -78,7 +78,9 @@ RootAccess::RootAccess(
     rtl::OUString const & locale, bool update):
     Access(components), pathRepresentation_(pathRepresentation),
     locale_(locale), update_(update)
-{}
+{
+    lock_ = lock();
+}
 
 Path RootAccess::getAbsolutePath() {
     getNode();
@@ -129,7 +131,7 @@ bool RootAccess::isUpdate() const {
 }
 
 RootAccess::~RootAccess() {
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     getComponents().removeRootAccess(this);
 }
 
@@ -227,7 +229,7 @@ css::uno::Any RootAccess::queryInterface(css::uno::Type const & aType)
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     css::uno::Any res(Access::queryInterface(aType));
     if (res.hasValue()) {
@@ -251,7 +253,7 @@ void RootAccess::addChangesListener(
 {
     OSL_ASSERT(thisIs(IS_ANY));
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         if (!aListener.is()) {
             throw css::uno::RuntimeException(
@@ -274,7 +276,7 @@ void RootAccess::removeChangesListener(
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_ANY));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     ChangesListeners::iterator i(changesListeners_.find(aListener));
     if (i != changesListeners_.end()) {
@@ -288,7 +290,7 @@ void RootAccess::commitChanges()
     OSL_ASSERT(thisIs(IS_UPDATE));
     Broadcaster bc;
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         checkLocalizedPropertyAccess();
         int finalizedLayer;
         Modifications globalMods;
@@ -306,7 +308,7 @@ void RootAccess::commitChanges()
 
 sal_Bool RootAccess::hasPendingChanges() throw (css::uno::RuntimeException) {
     OSL_ASSERT(thisIs(IS_UPDATE));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     //TODO: Optimize:
     std::vector< css::util::ElementChange > changes;
@@ -318,7 +320,7 @@ css::util::ChangesSet RootAccess::getPendingChanges()
     throw (css::uno::RuntimeException)
 {
     OSL_ASSERT(thisIs(IS_UPDATE));
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     checkLocalizedPropertyAccess();
     comphelper::SequenceAsVector< css::util::ElementChange > changes;
     reportChildChanges(&changes);
diff --git a/configmgr/source/rootaccess.hxx b/configmgr/source/rootaccess.hxx
index c7300c4..4d74167 100644
--- a/configmgr/source/rootaccess.hxx
+++ b/configmgr/source/rootaccess.hxx
@@ -39,6 +39,7 @@
 #include "com/sun/star/util/ChangesSet.hpp"
 #include "com/sun/star/util/XChangesBatch.hpp"
 #include "com/sun/star/util/XChangesNotifier.hpp"
+#include "boost/shared_ptr.hpp"
 #include "rtl/ref.hxx"
 #include "rtl/ustring.hxx"
 #include "sal/types.h"
@@ -151,6 +152,8 @@ private:
     rtl::OUString name_;
     bool finalized_;
     ChangesListeners changesListeners_;
+
+    boost::shared_ptr<osl::Mutex> lock_;
 };
 
 }
diff --git a/configmgr/source/update.cxx b/configmgr/source/update.cxx
index 53eff2c..7208eb3 100644
--- a/configmgr/source/update.cxx
+++ b/configmgr/source/update.cxx
@@ -32,6 +32,7 @@
 #include <set>
 
 #include "boost/noncopyable.hpp"
+#include "boost/shared_ptr.hpp"
 #include "com/sun/star/configuration/XUpdate.hpp"
 #include "com/sun/star/lang/XSingleComponentFactory.hpp"
 #include "com/sun/star/uno/Any.hxx"
@@ -77,7 +78,10 @@ class Service:
     private boost::noncopyable
 {
 public:
-    Service() {}
+    Service()
+    {
+        lock_ = lock();
+    }
 
 private:
     virtual ~Service() {}
@@ -98,13 +102,15 @@ private:
         css::uno::Sequence< rtl::OUString > const & includedPaths,
         css::uno::Sequence< rtl::OUString > const & excludedPaths)
         throw (css::uno::RuntimeException);
+
+    boost::shared_ptr<osl::Mutex> lock_;
 };
 
 void Service::insertExtensionXcsFile(
     sal_Bool shared, rtl::OUString const & fileUri)
     throw (css::uno::RuntimeException)
 {
-    osl::MutexGuard g(lock);
+    osl::MutexGuard g(*lock_);
     Components::getSingleton().insertExtensionXcsFile(shared, fileUri);
 }
 
@@ -114,7 +120,7 @@ void Service::insertExtensionXcuFile(
 {
     Broadcaster bc;
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         Modifications mods;
         Components::getSingleton().insertExtensionXcuFile(
             shared, fileUri, &mods);
@@ -129,7 +135,7 @@ void Service::removeExtensionXcuFile(rtl::OUString const & fileUri)
 {
     Broadcaster bc;
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         Modifications mods;
         Components::getSingleton().removeExtensionXcuFile(fileUri, &mods);
         Components::getSingleton().initGlobalBroadcaster(
@@ -146,7 +152,7 @@ void Service::insertModificationXcuFile(
 {
     Broadcaster bc;
     {
-        osl::MutexGuard g(lock);
+        osl::MutexGuard g(*lock_);
         Modifications mods;
         Components::getSingleton().insertModificationXcuFile(
             fileUri, seqToSet(includedPaths), seqToSet(excludedPaths), &mods);


More information about the Libreoffice-commits mailing list