diff options
author | Xisco Fauli <anistenis@gmail.com> | 2016-05-29 21:10:21 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-06-10 07:03:27 +0000 |
commit | 5f1b9ae3994282ec1be3690292957b8b99032e2d (patch) | |
tree | 61710695dbcc238a766999ae319eccc213ce1631 /svl | |
parent | svx: implement per-view LOK_CALLBACK_INVALIDATE_TILES (diff) | |
download | core-5f1b9ae3994282ec1be3690292957b8b99032e2d.tar.gz core-5f1b9ae3994282ec1be3690292957b8b99032e2d.zip |
tdf#89329: use shared_ptr for pImpl in cjkoptions
Change-Id: I0ad43869d24e210b3591af25f108c68ed8f6160b
Reviewed-on: https://gerrit.libreoffice.org/25634
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'svl')
-rw-r--r-- | svl/source/config/cjkoptions.cxx | 60 |
1 files changed, 30 insertions, 30 deletions
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: */ |