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

Michael Stahl mstahl at redhat.com
Wed Aug 3 11:28:18 UTC 2016


 dbaccess/source/core/dataaccess/ModelImpl.hxx |   22 ++++++++++++++++++++--
 dbaccess/source/ui/app/AppController.cxx      |    1 +
 2 files changed, 21 insertions(+), 2 deletions(-)

New commits:
commit 403eefe81b8a0afe888c60452c17d6b2c5d8343f
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Jul 27 15:02:52 2016 +0200

    tdf#101136 dbaccess: use SolarMutex in ModelMethodGuard
    
    There is a deadlock here when storing a ODatabaseDocument on a
    non-main-thread while the main thread dispatches some event that calls
    into ODatabaseDocument, while holding SolarMutex.
    
    The storing of the document also stores BASIC libraries, and since
    commit fca62934f492125ea6728fd6d09f0c66c9e4fa69 the SfxLibraryContainer
    uses SolarMutex for locking.
    
    Now we could re-investigate that problem, but it seems unrealistic to
    expect ODatabaseDocument's implementation will never call anything
    that acquires SolarMutex.
    
    Resistance is futile.  Your locking scheme will be assimilated.
    
    Change-Id: I337d286f3e96c6b2e0dde8682b31faab3f508d20
    Reviewed-on: https://gerrit.libreoffice.org/27590
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>

diff --git a/dbaccess/source/core/dataaccess/ModelImpl.hxx b/dbaccess/source/core/dataaccess/ModelImpl.hxx
index c57042d..439e7ae 100644
--- a/dbaccess/source/core/dataaccess/ModelImpl.hxx
+++ b/dbaccess/source/core/dataaccess/ModelImpl.hxx
@@ -66,6 +66,7 @@
 #include <connectivity/CommonTools.hxx>
 #include <cppuhelper/propshlp.hxx>
 #include <cppuhelper/weakref.hxx>
+#include <vcl/svapp.hxx>
 #include <sfx2/docmacromode.hxx>
 #include <sfx2/docstoragemodifylistener.hxx>
 #include <unotools/sharedunocomponent.hxx>
@@ -569,9 +570,13 @@ private:
     Just put this guard onto the stack at the beginning of your method. Don't bother yourself
     with a MutexGuard, checks for being disposed, and the like.
 */
-class ModelMethodGuard : public ::osl::ResettableMutexGuard
+class ModelMethodGuard
 {
 private:
+    // to avoid deadlocks, lock SolarMutex too, and before the own osl::Mutex
+    SolarMutexResettableGuard m_SolarGuard;
+    ::osl::ResettableMutexGuard m_OslGuard;
+
     typedef ::osl::ResettableMutexGuard             BaseMutexGuard;
 
 public:
@@ -584,11 +589,24 @@ public:
             If the given component is already disposed
     */
     explicit ModelMethodGuard( const ModelDependentComponent& _component )
-        :BaseMutexGuard( _component.getMutex( ModelDependentComponent::GuardAccess() ) )
+        : m_OslGuard(_component.getMutex(ModelDependentComponent::GuardAccess()))
     {
         _component.checkDisposed();
     }
 
+    void clear()
+    {
+        m_OslGuard.clear();
+        // note: this only releases *once* so may still be locked
+        m_SolarGuard.clear(); // SolarMutex last
+    }
+
+    void reset()
+    {
+        m_SolarGuard.reset(); // SolarMutex first
+        m_OslGuard.reset();
+    }
+
     ~ModelMethodGuard()
     {
     }
diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx
index ed47cff..d1206dc 100644
--- a/dbaccess/source/ui/app/AppController.cxx
+++ b/dbaccess/source/ui/app/AppController.cxx
@@ -2584,6 +2584,7 @@ void OApplicationController::OnFirstControllerConnected()
 
 void SAL_CALL OApplicationController::attachFrame( const Reference< XFrame > & i_rxFrame ) throw( RuntimeException, std::exception )
 {
+    SolarMutexGuard aSolarGuard; // avoid deadlock in XModel calls
     ::osl::MutexGuard aGuard( getMutex() );
 
     OGenericUnoController::attachFrame( i_rxFrame );


More information about the Libreoffice-commits mailing list