diff options
author | Xisco Fauli <anistenis@gmail.com> | 2016-06-14 02:04:06 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-06-14 11:18:27 +0000 |
commit | 7a60b2f3deaeced4352152525d1bb511a26b42bb (patch) | |
tree | f3fc59ba543c1b0d097148aa433661db238d945c /unotools | |
parent | e8c8d824607bdad288680678f259b3e78308bab0 (diff) |
tdf#89329: use shared_ptr for pImpl in defaultoptions...
instead of unique_ptr as in commit
7bc1c79c26e52d5196fb36eee5c2f12f12d49ba6
Change-Id: I4e57378a333455b818162c6cc8484be9dcaddb03
Reviewed-on: https://gerrit.libreoffice.org/26236
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/source/config/defaultoptions.cxx | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/unotools/source/config/defaultoptions.cxx b/unotools/source/config/defaultoptions.cxx index 6f021d4240c4..8a99dc5540fb 100644 --- a/unotools/source/config/defaultoptions.cxx +++ b/unotools/source/config/defaultoptions.cxx @@ -93,6 +93,7 @@ public: OUString m_aUserDictionaryPath; SvtDefaultOptions_Impl(); + ~SvtDefaultOptions_Impl(); OUString GetDefaultPath( sal_uInt16 nId ) const; virtual void Notify( const css::uno::Sequence<OUString>& aPropertyNames) override; @@ -103,8 +104,7 @@ private: // global ---------------------------------------------------------------- -static SvtDefaultOptions_Impl* pOptions = nullptr; -static sal_Int32 nRefCount = 0; +std::weak_ptr<SvtDefaultOptions_Impl> pOptions; typedef OUString SvtDefaultOptions_Impl:: *PathStrPtr; @@ -313,6 +313,12 @@ SvtDefaultOptions_Impl::SvtDefaultOptions_Impl() : ConfigItem( "Office.Common/Pa } } +SvtDefaultOptions_Impl::~SvtDefaultOptions_Impl() +{ + if ( IsModified() ) + Commit(); +} + // class SvtDefaultOptions ----------------------------------------------- namespace { struct lclMutex : public rtl::Static< ::osl::Mutex, lclMutex > {}; } @@ -320,25 +326,20 @@ SvtDefaultOptions::SvtDefaultOptions() { // Global access, must be guarded (multithreading) ::osl::MutexGuard aGuard( lclMutex::get() ); - if ( !pOptions ) + pImpl = pOptions.lock(); + if ( !pImpl ) { - pOptions = new SvtDefaultOptions_Impl; + pImpl = std::make_shared<SvtDefaultOptions_Impl>(); + pOptions = pImpl; ItemHolder1::holdConfigItem(E_DEFAULTOPTIONS); } - ++nRefCount; - pImpl.reset(pOptions); } SvtDefaultOptions::~SvtDefaultOptions() { // Global access, must be guarded (multithreading) ::osl::MutexGuard aGuard( lclMutex::get() ); - if ( !--nRefCount ) - { - if ( pOptions->IsModified() ) - pOptions->Commit(); - DELETEZ( pOptions ); - } + pImpl.reset(); } OUString SvtDefaultOptions::GetDefaultPath( sal_uInt16 nId ) const |