diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2011-12-16 17:06:42 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2011-12-16 17:14:35 +0100 |
commit | c5cf78e1529970c04e1999e1f96f3e374ecd211e (patch) | |
tree | 300f2baaf448ccf3fad8b4bb2864c3c2ca45d9f0 /linguistic | |
parent | 9bdfd1fa4dde2f4901900f7447b588c2640ff3f4 (diff) |
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...
Diffstat (limited to 'linguistic')
-rw-r--r-- | linguistic/source/gciterator.cxx | 61 | ||||
-rw-r--r-- | linguistic/source/gciterator.hxx | 5 |
2 files changed, 32 insertions, 34 deletions
diff --git a/linguistic/source/gciterator.cxx b/linguistic/source/gciterator.cxx index 98280520a682..91c407ca8e74 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 aab04dd6f0ae..8dda00971437 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 ); |