tdf#89329: use shared_ptr for pImpl in defaultoptions...
instead of unique_ptr as in commit
7bc1c79c26
Change-Id: I4e57378a333455b818162c6cc8484be9dcaddb03
Reviewed-on: https://gerrit.libreoffice.org/26236
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
This commit is contained in:
committed by
Noel Grandin
parent
e8c8d82460
commit
7a60b2f3de
@@ -30,7 +30,7 @@ class SvtDefaultOptions_Impl;
|
|||||||
class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtDefaultOptions : public utl::detail::Options
|
class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtDefaultOptions : public utl::detail::Options
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<SvtDefaultOptions_Impl> pImpl;
|
std::shared_ptr<SvtDefaultOptions_Impl> pImpl;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@@ -93,6 +93,7 @@ public:
|
|||||||
OUString m_aUserDictionaryPath;
|
OUString m_aUserDictionaryPath;
|
||||||
|
|
||||||
SvtDefaultOptions_Impl();
|
SvtDefaultOptions_Impl();
|
||||||
|
~SvtDefaultOptions_Impl();
|
||||||
|
|
||||||
OUString GetDefaultPath( sal_uInt16 nId ) const;
|
OUString GetDefaultPath( sal_uInt16 nId ) const;
|
||||||
virtual void Notify( const css::uno::Sequence<OUString>& aPropertyNames) override;
|
virtual void Notify( const css::uno::Sequence<OUString>& aPropertyNames) override;
|
||||||
@@ -103,8 +104,7 @@ private:
|
|||||||
|
|
||||||
// global ----------------------------------------------------------------
|
// global ----------------------------------------------------------------
|
||||||
|
|
||||||
static SvtDefaultOptions_Impl* pOptions = nullptr;
|
std::weak_ptr<SvtDefaultOptions_Impl> pOptions;
|
||||||
static sal_Int32 nRefCount = 0;
|
|
||||||
|
|
||||||
typedef OUString SvtDefaultOptions_Impl:: *PathStrPtr;
|
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 -----------------------------------------------
|
// class SvtDefaultOptions -----------------------------------------------
|
||||||
namespace { struct lclMutex : public rtl::Static< ::osl::Mutex, lclMutex > {}; }
|
namespace { struct lclMutex : public rtl::Static< ::osl::Mutex, lclMutex > {}; }
|
||||||
|
|
||||||
@@ -320,25 +326,20 @@ SvtDefaultOptions::SvtDefaultOptions()
|
|||||||
{
|
{
|
||||||
// Global access, must be guarded (multithreading)
|
// Global access, must be guarded (multithreading)
|
||||||
::osl::MutexGuard aGuard( lclMutex::get() );
|
::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);
|
ItemHolder1::holdConfigItem(E_DEFAULTOPTIONS);
|
||||||
}
|
}
|
||||||
++nRefCount;
|
|
||||||
pImpl.reset(pOptions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SvtDefaultOptions::~SvtDefaultOptions()
|
SvtDefaultOptions::~SvtDefaultOptions()
|
||||||
{
|
{
|
||||||
// Global access, must be guarded (multithreading)
|
// Global access, must be guarded (multithreading)
|
||||||
::osl::MutexGuard aGuard( lclMutex::get() );
|
::osl::MutexGuard aGuard( lclMutex::get() );
|
||||||
if ( !--nRefCount )
|
pImpl.reset();
|
||||||
{
|
|
||||||
if ( pOptions->IsModified() )
|
|
||||||
pOptions->Commit();
|
|
||||||
DELETEZ( pOptions );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OUString SvtDefaultOptions::GetDefaultPath( sal_uInt16 nId ) const
|
OUString SvtDefaultOptions::GetDefaultPath( sal_uInt16 nId ) const
|
||||||
|
Reference in New Issue
Block a user