summaryrefslogtreecommitdiff
path: root/dbaccess
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2016-07-27 15:02:52 +0200
committerMichael Stahl <mstahl@redhat.com>2016-08-03 11:27:44 +0000
commit403eefe81b8a0afe888c60452c17d6b2c5d8343f (patch)
tree9575751bd99e6992ccbfacd5cb8fd705d3866519 /dbaccess
parent4acac00df5a85ff006ecead06c4018e88caaf401 (diff)
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@libreoffice.org> Reviewed-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'dbaccess')
-rw-r--r--dbaccess/source/core/dataaccess/ModelImpl.hxx22
-rw-r--r--dbaccess/source/ui/app/AppController.cxx1
2 files changed, 21 insertions, 2 deletions
diff --git a/dbaccess/source/core/dataaccess/ModelImpl.hxx b/dbaccess/source/core/dataaccess/ModelImpl.hxx
index c57042dc928e..439e7ae3a370 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 ed47cffb5fe4..d1206dcbc959 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 );