create method for doing the "dispose-on-destruct"
which is (a) a little tricky and (b) needs to be on the base class to get the locking just right Change-Id: I425d4747e7e0ca0741fded9a6a70f6fa9995e102 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174312 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
parent
9939f5cbf0
commit
fc0cb364ae
3 changed files with 19 additions and 7 deletions
|
@ -105,13 +105,7 @@ namespace basctl
|
|||
|
||||
DocumentEventNotifier::Impl::~Impl ()
|
||||
{
|
||||
std::unique_lock aGuard(m_aMutex);
|
||||
if ( !impl_isDisposed_nothrow(aGuard) )
|
||||
{
|
||||
acquire();
|
||||
aGuard.unlock(); // dispose locks m_aMutex
|
||||
dispose();
|
||||
}
|
||||
disposeOnDestruct();
|
||||
}
|
||||
|
||||
void SAL_CALL DocumentEventNotifier::Impl::documentEventOccured( const DocumentEvent& _rEvent )
|
||||
|
|
|
@ -30,6 +30,21 @@ void SAL_CALL WeakComponentImplHelperBase::dispose()
|
|||
maEventListeners.disposeAndClear(aGuard, aEvt);
|
||||
}
|
||||
|
||||
// This is only called from the destructor to do cleanup that
|
||||
// might not have occurred
|
||||
void WeakComponentImplHelperBase::disposeOnDestruct()
|
||||
{
|
||||
std::unique_lock aGuard(m_aMutex);
|
||||
assert(m_refCount == 0 && "only supposed to be called from the destructor");
|
||||
if (m_bDisposed)
|
||||
return;
|
||||
m_bDisposed = true;
|
||||
// bump the ref-count so we dont accidentally do a double delete
|
||||
// if something else increases and then decreases our ref-count
|
||||
cppu::OWeakObject::acquire();
|
||||
disposing(aGuard);
|
||||
}
|
||||
|
||||
void WeakComponentImplHelperBase::disposing(std::unique_lock<std::mutex>&) {}
|
||||
|
||||
void SAL_CALL WeakComponentImplHelperBase::addEventListener(
|
||||
|
|
|
@ -56,6 +56,9 @@ protected:
|
|||
if (m_bDisposed)
|
||||
throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject*>(this));
|
||||
}
|
||||
// only to be called from the destructor, to run the dispose logic, if necessary
|
||||
void disposeOnDestruct();
|
||||
|
||||
comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> maEventListeners;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue