[Libreoffice-commits] .: linguistic/source vcl/source

Stephan Bergmann sbergmann at kemper.freedesktop.org
Fri Dec 16 08:15:19 PST 2011


 linguistic/source/gciterator.cxx |   61 +++++++++++++++++----------------------
 linguistic/source/gciterator.hxx |    5 ++-
 vcl/source/app/svmain.cxx        |    4 ++
 3 files changed, 36 insertions(+), 34 deletions(-)

New commits:
commit c5cf78e1529970c04e1999e1f96f3e374ecd211e
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Dec 16 17:06:42 2011 +0100

    Properly join spawned GrammarCheckingIterator thread.
    
    It was still running during shutdown of sw_complex's checkFlies test, causing
    problems.
    For this to work, Desktop::DeInit needs to be called with SolarMutex unlocked,
    which looks like the right way, anyway.  Hopefully it does not unearth another
    round of bugs...

diff --git a/linguistic/source/gciterator.cxx b/linguistic/source/gciterator.cxx
index 9828052..91c407c 100644
--- a/linguistic/source/gciterator.cxx
+++ b/linguistic/source/gciterator.cxx
@@ -252,15 +252,31 @@ GrammarCheckingIterator::GrammarCheckingIterator( const uno::Reference< lang::XM
     m_aEventListeners( MyMutex::get() ),
     m_aNotifyListeners( MyMutex::get() )
 {
-    osl_createThread( workerfunc, this );
+    m_thread = osl_createThread( workerfunc, this );
 }
 
 
 GrammarCheckingIterator::~GrammarCheckingIterator()
 {
-    ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() );
+    TerminateThread();
 }
 
+void GrammarCheckingIterator::TerminateThread()
+{
+    oslThread t;
+    {
+        ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() );
+        t = m_thread;
+        m_thread = 0;
+        m_bEnd = sal_True;
+        m_aWakeUpThread.set();
+    }
+    if (t != 0)
+    {
+        osl_joinWithThread(t);
+        osl_destroyThread(t);
+    }
+}
 
 sal_Int32 GrammarCheckingIterator::NextDocId()
 {
@@ -489,19 +505,16 @@ void GrammarCheckingIterator::DequeueAndCheck()
     uno::Sequence< sal_Int32 >      aLangPortions;
     uno::Sequence< lang::Locale >   aLangPortionsLocale;
 
-    // ---- THREAD SAFE START ----
-    bool bEnd = false;
-    {
-        ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() );
-        bEnd = m_bEnd;
-    }
-    // ---- THREAD SAFE END ----
-    while (!bEnd)
+    for (;;)
     {
         // ---- THREAD SAFE START ----
         bool bQueueEmpty = false;
         {
             ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() );
+            if (m_bEnd)
+            {
+                break;
+            }
             bQueueEmpty = m_aFPEntriesQueue.empty();
         }
         // ---- THREAD SAFE END ----
@@ -605,6 +618,10 @@ void GrammarCheckingIterator::DequeueAndCheck()
             // ---- THREAD SAFE START ----
             {
                 ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() );
+                if (m_bEnd)
+                {
+                    break;
+                }
                 // Check queue state again
                 if (m_aFPEntriesQueue.empty())
                     m_aWakeUpThread.reset();
@@ -618,17 +635,7 @@ void GrammarCheckingIterator::DequeueAndCheck()
             // safe implemented.
             m_aWakeUpThread.wait();
         }
-
-        // ---- THREAD SAFE START ----
-        {
-            ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() );
-            bEnd = m_bEnd;
-        }
-        // ---- THREAD SAFE END ----
     }
-
-    //!! This one must be the very last statement to call in this function !!
-    m_aRequestEndThread.set();
 }
 
 
@@ -901,19 +908,7 @@ throw (uno::RuntimeException)
     lang::EventObject aEvt( (linguistic2::XProofreadingIterator *) this );
     m_aEventListeners.disposeAndClear( aEvt );
 
-    // now end the thread...
-    m_aRequestEndThread.reset();
-    // ---- THREAD SAFE START ----
-    {
-        ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() );
-        m_bEnd = sal_True;
-    }
-    // ---- THREAD SAFE END ----
-    m_aWakeUpThread.set();
-    const TimeValue aTime = { 3, 0 };   // wait 3 seconds...
-    m_aRequestEndThread.wait( &aTime );
-    // if the call ends because of time-out we will end anyway...
-
+    TerminateThread();
 
     // ---- THREAD SAFE START ----
     {
diff --git a/linguistic/source/gciterator.hxx b/linguistic/source/gciterator.hxx
index aab04dd..8dda009 100644
--- a/linguistic/source/gciterator.hxx
+++ b/linguistic/source/gciterator.hxx
@@ -43,6 +43,7 @@
 #include <cppuhelper/weakref.hxx>
 #include <osl/mutex.hxx>
 #include <osl/conditn.hxx>
+#include <osl/thread.h>
 #include <rtl/instance.hxx>
 
 #include <map>
@@ -122,7 +123,7 @@ class GrammarCheckingIterator:
     sal_Int32       m_nDocIdCounter;
     sal_Int32       m_nLastEndOfSentencePos;
     osl::Condition  m_aWakeUpThread;
-    osl::Condition  m_aRequestEndThread;
+    oslThread       m_thread;
 
     //! beware of initilization order !
     struct MyMutex : public rtl::Static< osl::Mutex, MyMutex > {};
@@ -132,6 +133,8 @@ class GrammarCheckingIterator:
     ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > m_xBreakIterator;
     mutable ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesBatch >  m_xUpdateAccess;
 
+    void TerminateThread();
+
     sal_Int32 NextDocId();
     ::rtl::OUString GetOrCreateDocId( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > &xComp );
 
diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx
index 5ab01b9..cf98fb8 100644
--- a/vcl/source/app/svmain.cxx
+++ b/vcl/source/app/svmain.cxx
@@ -489,10 +489,14 @@ void DeInitVCL()
     pSVData->maAppData.mxMSF.clear();
 
     if( pSVData->mpApp )
+    {
+        sal_uLong nCount = Application::ReleaseSolarMutex();
         // call deinit to deinitialize application class
         // soffice/sfx implementation disposes the global service manager
         // Warning: After this call you can't call uno services
         pSVData->mpApp->DeInit();
+        Application::AcquireSolarMutex(nCount);
+    }
 
     if ( pSVData->maAppData.mpSettings )
     {


More information about the Libreoffice-commits mailing list