Kaydet (Commit) 13b60fd8 authored tarafından Michael Stahl's avatar Michael Stahl

ucb: NeonLockStore::stopTicker(): really avoid deadlock

Follow up on 68ba2785, which missed the
sad fact that m_aMutex is locked recursively.

Avoid that by passing a ClearableMutexGuard to stopTicker() and
unlocking that.  Also lock m_aMutex in the destructor while at it.

Change-Id: I5ef7ef8f15e2b5c9810c5ffc64ed922ab9ad2807
üst 40ae8f36
......@@ -93,7 +93,9 @@ NeonLockStore::NeonLockStore()
NeonLockStore::~NeonLockStore()
{
stopTicker();
osl::ResettableMutexGuard aGuard(m_aMutex);
stopTicker(aGuard);
aGuard.reset(); // actually no threads should even try to access members now
// release active locks, if any.
OSL_ENSURE( m_aLockInfoMap.empty(),
......@@ -126,23 +128,22 @@ void NeonLockStore::startTicker()
}
}
void NeonLockStore::stopTicker()
void NeonLockStore::stopTicker(osl::ClearableMutexGuard & rGuard)
{
rtl::Reference<TickerThread> pTickerThread;
{
osl::MutexGuard aGuard( m_aMutex );
if (!m_pTickerThread.is())
{
return; // nothing to do
}
if (m_pTickerThread.is())
{
m_pTickerThread->finish(); // needs mutex
// the TickerThread may run refreshLocks() at most once after this
pTickerThread = m_pTickerThread;
m_pTickerThread.clear();
}
pTickerThread->join(); // without m_aMutex locked (to prevent deadlock)
rGuard.clear();
if (pTickerThread.is())
pTickerThread->join(); // without m_aMutex locked (to prevent deadlock)
}
void NeonLockStore::registerSession( HttpSession * pHttpSession )
......@@ -193,13 +194,13 @@ void NeonLockStore::updateLock( NeonLock * pLock,
void NeonLockStore::removeLock( NeonLock * pLock )
{
osl::MutexGuard aGuard( m_aMutex );
osl::ClearableMutexGuard aGuard( m_aMutex );
m_aLockInfoMap.erase( pLock );
ne_lockstore_remove( m_pNeonLockStore, pLock );
if ( m_aLockInfoMap.empty() )
stopTicker();
stopTicker(aGuard);
}
void NeonLockStore::refreshLocks()
......
......@@ -96,7 +96,7 @@ public:
private:
void startTicker();
void stopTicker();
void stopTicker(osl::ClearableMutexGuard & rGuard);
};
} // namespace webdav_ucp
......
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