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

Follow up on 68ba2785c5, 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
This commit is contained in:
Michael Stahl
2013-05-30 17:13:50 +02:00
parent 40ae8f365b
commit 13b60fd80a
2 changed files with 13 additions and 12 deletions

View File

@@ -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()

View File

@@ -96,7 +96,7 @@ public:
private:
void startTicker();
void stopTicker();
void stopTicker(osl::ClearableMutexGuard & rGuard);
};
} // namespace webdav_ucp