diff options
-rw-r--r-- | include/svl/cjkoptions.hxx | 3 | ||||
-rw-r--r-- | svl/source/config/cjkoptions.cxx | 60 |
2 files changed, 32 insertions, 31 deletions
diff --git a/include/svl/cjkoptions.hxx b/include/svl/cjkoptions.hxx index a599e8406882..e35cfb2bfe27 100644 --- a/include/svl/cjkoptions.hxx +++ b/include/svl/cjkoptions.hxx @@ -22,6 +22,7 @@ #include <svl/svldllapi.h> #include <sal/types.h> #include <unotools/options.hxx> +#include <memory> class SvtCJKOptions_Impl; @@ -30,7 +31,7 @@ class SvtCJKOptions_Impl; class SVL_DLLPUBLIC SvtCJKOptions: public utl::detail::Options { private: - SvtCJKOptions_Impl* pImp; + std::shared_ptr<SvtCJKOptions_Impl> pImpl; public: diff --git a/svl/source/config/cjkoptions.cxx b/svl/source/config/cjkoptions.cxx index 3c7d9f201cc6..3eba25b826d3 100644 --- a/svl/source/config/cjkoptions.cxx +++ b/svl/source/config/cjkoptions.cxx @@ -377,25 +377,24 @@ bool SvtCJKOptions_Impl::IsReadOnly(SvtCJKOptions::EOption eOption) const } // global +std::weak_ptr<SvtCJKOptions_Impl> pCJKOptions; -static SvtCJKOptions_Impl* pCJKOptions = nullptr; -static sal_Int32 nCJKRefCount = 0; namespace { struct theCJKOptionsMutex : public rtl::Static< ::osl::Mutex , theCJKOptionsMutex >{}; } SvtCJKOptions::SvtCJKOptions(bool bDontLoad) { // Global access, must be guarded (multithreading) ::osl::MutexGuard aGuard( theCJKOptionsMutex::get() ); - if ( !pCJKOptions ) + pImpl = pCJKOptions.lock(); + if ( !pImpl ) { - pCJKOptions = new SvtCJKOptions_Impl; + pImpl = std::make_shared<SvtCJKOptions_Impl>(); + pCJKOptions = pImpl; ItemHolder2::holdConfigItem(E_CJKOPTIONS); } - if( !bDontLoad && !pCJKOptions->IsLoaded()) - pCJKOptions->Load(); - ++nCJKRefCount; - pImp = pCJKOptions; + if( !bDontLoad && !pImpl->IsLoaded()) + pImpl->Load(); } @@ -403,68 +402,69 @@ SvtCJKOptions::~SvtCJKOptions() { // Global access, must be guarded (multithreading) ::osl::MutexGuard aGuard( theCJKOptionsMutex::get() ); - if ( !--nCJKRefCount ) - DELETEZ( pCJKOptions ); + + // pImpl needs to be cleared before the mutex is dropped + pImpl.reset(); } bool SvtCJKOptions::IsCJKFontEnabled() const { - assert(pCJKOptions->IsLoaded()); - return pCJKOptions->IsCJKFontEnabled(); + assert(pImpl->IsLoaded()); + return pImpl->IsCJKFontEnabled(); } bool SvtCJKOptions::IsVerticalTextEnabled() const { - assert(pCJKOptions->IsLoaded()); - return pCJKOptions->IsVerticalTextEnabled(); + assert(pImpl->IsLoaded()); + return pImpl->IsVerticalTextEnabled(); } bool SvtCJKOptions::IsAsianTypographyEnabled() const { - assert(pCJKOptions->IsLoaded()); - return pCJKOptions->IsAsianTypographyEnabled(); + assert(pImpl->IsLoaded()); + return pImpl->IsAsianTypographyEnabled(); } bool SvtCJKOptions::IsJapaneseFindEnabled() const { - assert(pCJKOptions->IsLoaded()); - return pCJKOptions->IsJapaneseFindEnabled(); + assert(pImpl->IsLoaded()); + return pImpl->IsJapaneseFindEnabled(); } bool SvtCJKOptions::IsRubyEnabled() const { - assert(pCJKOptions->IsLoaded()); - return pCJKOptions->IsRubyEnabled(); + assert(pImpl->IsLoaded()); + return pImpl->IsRubyEnabled(); } bool SvtCJKOptions::IsChangeCaseMapEnabled() const { - assert(pCJKOptions->IsLoaded()); - return pCJKOptions->IsChangeCaseMapEnabled(); + assert(pImpl->IsLoaded()); + return pImpl->IsChangeCaseMapEnabled(); } bool SvtCJKOptions::IsDoubleLinesEnabled() const { - assert(pCJKOptions->IsLoaded()); - return pCJKOptions->IsDoubleLinesEnabled(); + assert(pImpl->IsLoaded()); + return pImpl->IsDoubleLinesEnabled(); } void SvtCJKOptions::SetAll(bool bSet) { - assert(pCJKOptions->IsLoaded()); - pCJKOptions->SetAll(bSet); + assert(pImpl->IsLoaded()); + pImpl->SetAll(bSet); } bool SvtCJKOptions::IsAnyEnabled() const { - assert(pCJKOptions->IsLoaded()); - return pCJKOptions->IsAnyEnabled(); + assert(pImpl->IsLoaded()); + return pImpl->IsAnyEnabled(); } bool SvtCJKOptions::IsReadOnly(EOption eOption) const { - assert(pCJKOptions->IsLoaded()); - return pCJKOptions->IsReadOnly(eOption); + assert(pImpl->IsLoaded()); + return pImpl->IsReadOnly(eOption); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |