Kaydet (Commit) 403eefe8 authored tarafından Michael Stahl's avatar Michael Stahl

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 fca62934 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/27590Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Stahl <mstahl@redhat.com>
üst 4acac00d
......@@ -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()
{
}
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment