diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-11-14 22:12:55 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-11-15 09:25:13 +0100 |
commit | 1badef89c0794167b9b84ea44d4a7df5645de8a7 (patch) | |
tree | 26dfe81507556143eaae904180e7499f2b51481f /linguistic/source | |
parent | 92857b181a715de08bd4264f4dc4161367d2b3c7 (diff) |
rtl::Static->thread-safe static in linguistic
Change-Id: Ie028e0d93f4dec4974d357900a2d5d84275a9a8e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125209
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'linguistic/source')
-rw-r--r-- | linguistic/source/convdiclist.cxx | 14 | ||||
-rw-r--r-- | linguistic/source/gciterator.cxx | 44 | ||||
-rw-r--r-- | linguistic/source/gciterator.hxx | 3 | ||||
-rw-r--r-- | linguistic/source/misc.cxx | 15 |
4 files changed, 35 insertions, 41 deletions
diff --git a/linguistic/source/convdiclist.cxx b/linguistic/source/convdiclist.cxx index 43d75141bc01..54517960f062 100644 --- a/linguistic/source/convdiclist.cxx +++ b/linguistic/source/convdiclist.cxx @@ -33,7 +33,6 @@ #include <comphelper/processfactory.hxx> #include <comphelper/sequence.hxx> #include <cppuhelper/supportsservice.hxx> -#include <rtl/instance.hxx> #include <tools/debug.hxx> #include <tools/urlobj.hxx> #include <ucbhelper/content.hxx> @@ -312,18 +311,17 @@ void ConvDicNameContainer::AddConvDics( namespace { - struct StaticConvDicList : public rtl::StaticWithInit< - rtl::Reference<ConvDicList>, StaticConvDicList> { - rtl::Reference<ConvDicList> operator () () { - return new ConvDicList; - } + rtl::Reference<ConvDicList>& StaticConvDicList() + { + static rtl::Reference<ConvDicList> SINGLETON = new ConvDicList; + return SINGLETON; }; } void ConvDicList::MyAppExitListener::AtExit() { rMyDicList.FlushDics(); - StaticConvDicList::get().clear(); + StaticConvDicList().clear(); } ConvDicList::ConvDicList() : @@ -535,7 +533,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* linguistic_ConvDicList_get_implementation( css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&) { - return cppu::acquire(StaticConvDicList::get().get()); + return cppu::acquire(StaticConvDicList().get()); } diff --git a/linguistic/source/gciterator.cxx b/linguistic/source/gciterator.cxx index b915dee3033a..28336c5184a4 100644 --- a/linguistic/source/gciterator.cxx +++ b/linguistic/source/gciterator.cxx @@ -272,13 +272,19 @@ css::uno::Any SAL_CALL LngXStringKeyMap::getValueByIndex(::sal_Int32 nIndex) } +osl::Mutex& GrammarCheckingIterator::MyMutex() +{ + static osl::Mutex SINGLETON; + return SINGLETON; +} + GrammarCheckingIterator::GrammarCheckingIterator() : m_bEnd( false ), m_bGCServicesChecked( false ), m_nDocIdCounter( 0 ), m_thread(nullptr), - m_aEventListeners( MyMutex::get() ), - m_aNotifyListeners( MyMutex::get() ) + m_aEventListeners( MyMutex() ), + m_aNotifyListeners( MyMutex() ) { } @@ -292,7 +298,7 @@ void GrammarCheckingIterator::TerminateThread() { oslThread t; { - ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); + ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() ); t = m_thread; m_thread = nullptr; m_bEnd = true; @@ -307,7 +313,7 @@ void GrammarCheckingIterator::TerminateThread() sal_Int32 GrammarCheckingIterator::NextDocId() { - ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); + ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() ); m_nDocIdCounter += 1; return m_nDocIdCounter; } @@ -359,7 +365,7 @@ void GrammarCheckingIterator::AddEntry( aNewFPEntry.m_bAutomatic = bAutomatic; // add new entry to the end of this queue - ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); + ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() ); if (!m_thread) m_thread = osl_createThread( lcl_workerfunc, this ); m_aFPEntriesQueue.push_back( aNewFPEntry ); @@ -488,7 +494,7 @@ uno::Reference< linguistic2::XProofreader > GrammarCheckingIterator::GetGrammarC uno::Reference< linguistic2::XProofreader > xRes; // ---- THREAD SAFE START ---- - ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); + ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() ); // check supported locales for each grammarchecker if not already done if (!m_bGCServicesChecked) @@ -562,7 +568,7 @@ void GrammarCheckingIterator::DequeueAndCheck() // ---- THREAD SAFE START ---- bool bQueueEmpty = false; { - ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); + ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() ); if (m_bEnd) { break; @@ -579,7 +585,7 @@ void GrammarCheckingIterator::DequeueAndCheck() OUString aCurDocId; // ---- THREAD SAFE START ---- { - ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); + ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() ); aFPEntryItem = m_aFPEntriesQueue.front(); xFPIterator = aFPEntryItem.m_xParaIterator; xFlatPara = aFPEntryItem.m_xPara; @@ -604,7 +610,7 @@ void GrammarCheckingIterator::DequeueAndCheck() // ---- THREAD SAFE START ---- { - osl::ClearableMutexGuard aGuard(MyMutex::get()); + osl::ClearableMutexGuard aGuard(MyMutex()); sal_Int32 nStartPos = aFPEntryItem.m_nStartIndex; sal_Int32 nSuggestedEnd @@ -674,7 +680,7 @@ void GrammarCheckingIterator::DequeueAndCheck() // ---- THREAD SAFE START ---- { - ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); + ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() ); m_aCurCheckedDocId.clear(); } // ---- THREAD SAFE END ---- @@ -683,7 +689,7 @@ void GrammarCheckingIterator::DequeueAndCheck() { // ---- THREAD SAFE START ---- { - ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); + ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() ); if (m_bEnd) { break; @@ -717,7 +723,7 @@ void SAL_CALL GrammarCheckingIterator::startProofreading( uno::Reference< lang::XComponent > xComponent( xDoc, uno::UNO_QUERY ); // ---- THREAD SAFE START ---- - ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); + ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() ); if (xPara.is() && xComponent.is()) { OUString aDocId = GetOrCreateDocId( xComponent ); @@ -760,7 +766,7 @@ linguistic2::ProofreadingResult SAL_CALL GrammarCheckingIterator::checkSentenceA // ---- THREAD SAFE START ---- { - ::osl::ClearableGuard< ::osl::Mutex > aGuard( MyMutex::get() ); + ::osl::ClearableGuard< ::osl::Mutex > aGuard( MyMutex() ); aDocId = GetOrCreateDocId( xComponent ); nSuggestedEndOfSentencePos = GetSuggestedEndOfSentence( rText, nStartPos, aCurLocale ); DBG_ASSERT( nSuggestedEndOfSentencePos > nStartPos, "nSuggestedEndOfSentencePos calculation failed?" ); @@ -872,7 +878,7 @@ sal_Bool SAL_CALL GrammarCheckingIterator::isProofreading( const uno::Reference< uno::XInterface >& xDoc ) { // ---- THREAD SAFE START ---- - ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); + ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() ); bool bRes = false; @@ -970,7 +976,7 @@ void SAL_CALL GrammarCheckingIterator::dispose() // ---- THREAD SAFE START ---- { - ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); + ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() ); // release all UNO references @@ -1022,7 +1028,7 @@ void SAL_CALL GrammarCheckingIterator::disposing( const lang::EventObject &rSour if (xDoc.is()) { // ---- THREAD SAFE START ---- - ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); + ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() ); m_aDocIdMap.erase( xDoc.get() ); // ---- THREAD SAFE END ---- } @@ -1097,7 +1103,7 @@ void GrammarCheckingIterator::GetConfiguredGCSvcs_Impl() { // ---- THREAD SAFE START ---- - ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); + ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() ); m_aGCImplNamesByLang = aTmpGCImplNamesByLang; // ---- THREAD SAFE END ---- } @@ -1127,7 +1133,7 @@ void GrammarCheckingIterator::SetServiceList( const lang::Locale &rLocale, const uno::Sequence< OUString > &rSvcImplNames ) { - ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); + ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() ); LanguageType nLanguage = LinguLocaleToLanguage( rLocale ); OUString aImplName; @@ -1147,7 +1153,7 @@ void GrammarCheckingIterator::SetServiceList( uno::Sequence< OUString > GrammarCheckingIterator::GetServiceList( const lang::Locale &rLocale ) const { - ::osl::Guard< ::osl::Mutex > aGuard( MyMutex::get() ); + ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() ); OUString aImplName; // there is only one grammar checker per language LanguageType nLang = LinguLocaleToLanguage( rLocale ); diff --git a/linguistic/source/gciterator.hxx b/linguistic/source/gciterator.hxx index b0274aeac3c9..f7d43aace23f 100644 --- a/linguistic/source/gciterator.hxx +++ b/linguistic/source/gciterator.hxx @@ -34,7 +34,6 @@ #include <osl/mutex.hxx> #include <osl/conditn.hxx> #include <osl/thread.h> -#include <rtl/instance.hxx> #include <com/sun/star/uno/Any.hxx> #include <comphelper/interfacecontainer2.hxx> @@ -113,7 +112,7 @@ class GrammarCheckingIterator: oslThread m_thread; //! beware of initialization order! - struct MyMutex : public rtl::Static< osl::Mutex, MyMutex > {}; + static osl::Mutex& MyMutex(); comphelper::OInterfaceContainerHelper2 m_aEventListeners; comphelper::OInterfaceContainerHelper2 m_aNotifyListeners; diff --git a/linguistic/source/misc.cxx b/linguistic/source/misc.cxx index c2ff50b7f527..09635359d1ce 100644 --- a/linguistic/source/misc.cxx +++ b/linguistic/source/misc.cxx @@ -42,8 +42,6 @@ #include <svtools/strings.hrc> #include <unotools/resmgr.hxx> -#include <rtl/instance.hxx> - #include <linguistic/misc.hxx> #include <linguistic/hyphdta.hxx> #include <mutex> @@ -59,18 +57,11 @@ using namespace com::sun::star::linguistic2; namespace linguistic { -namespace { - //!! multi-thread safe mutex for all platforms !! -struct LinguMutex : public rtl::Static< osl::Mutex, LinguMutex > -{ -}; - -} - -osl::Mutex & GetLinguMutex() +osl::Mutex & GetLinguMutex() { - return LinguMutex::get(); + static osl::Mutex SINGLETON; + return SINGLETON; } const LocaleDataWrapper & GetLocaleDataWrapper( LanguageType nLang ) |