[Libreoffice-commits] core.git: ucb/source

Michael Stahl mstahl at redhat.com
Thu May 30 08:28:07 PDT 2013


 ucb/source/ucp/webdav-neon/NeonLockStore.cxx |   23 ++++++++++++-----------
 ucb/source/ucp/webdav-neon/NeonLockStore.hxx |    2 +-
 2 files changed, 13 insertions(+), 12 deletions(-)

New commits:
commit 13b60fd80a7adfb0ef81a818917cfec5edfc6edc
Author: Michael Stahl <mstahl at redhat.com>
Date:   Thu May 30 17:13:50 2013 +0200

    ucb: NeonLockStore::stopTicker(): really avoid deadlock
    
    Follow up on 68ba2785c55eaa1ea70ce135bdad5322b0e04ed7, 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

diff --git a/ucb/source/ucp/webdav-neon/NeonLockStore.cxx b/ucb/source/ucp/webdav-neon/NeonLockStore.cxx
index 043ea7d..890402c 100644
--- a/ucb/source/ucp/webdav-neon/NeonLockStore.cxx
+++ b/ucb/source/ucp/webdav-neon/NeonLockStore.cxx
@@ -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()
diff --git a/ucb/source/ucp/webdav-neon/NeonLockStore.hxx b/ucb/source/ucp/webdav-neon/NeonLockStore.hxx
index dd9b185..529158e 100644
--- a/ucb/source/ucp/webdav-neon/NeonLockStore.hxx
+++ b/ucb/source/ucp/webdav-neon/NeonLockStore.hxx
@@ -96,7 +96,7 @@ public:
 
 private:
     void startTicker();
-    void stopTicker();
+    void stopTicker(osl::ClearableMutexGuard & rGuard);
 };
 
 } // namespace webdav_ucp


More information about the Libreoffice-commits mailing list