summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorXisco Fauli <anistenis@gmail.com>2016-06-15 20:26:14 +0200
committerNoel Grandin <noelgrandin@gmail.com>2016-06-17 06:47:14 +0000
commita1f836e40d30fa39478e31ed8bc7bd947d4803c9 (patch)
tree1374fdc0a7d018e453c92d9fa73ef6b7c459f5bb /unotools
parentf35b1397ae3e7e975ea1c423df5c7a8ee711d335 (diff)
tdf#89329: use shared_ptr for pImpl in dynamicmenuoptions
Change-Id: I66bdeeee7f70e6ca16a39e8804aaf8a5f0d08205 Reviewed-on: https://gerrit.libreoffice.org/26327 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'unotools')
-rw-r--r--unotools/source/config/dynamicmenuoptions.cxx37
1 files changed, 12 insertions, 25 deletions
diff --git a/unotools/source/config/dynamicmenuoptions.cxx b/unotools/source/config/dynamicmenuoptions.cxx
index 38c94a1e76a1..1d95ca1f8877 100644
--- a/unotools/source/config/dynamicmenuoptions.cxx
+++ b/unotools/source/config/dynamicmenuoptions.cxx
@@ -566,44 +566,31 @@ void SvtDynamicMenuOptions_Impl::impl_SortAndExpandPropertyNames( const Sequence
}
}
-// initialize static member
-// DON'T DO IT IN YOUR HEADER!
-// see definition for further information
-
-SvtDynamicMenuOptions_Impl* SvtDynamicMenuOptions::m_pDataContainer = nullptr;
-sal_Int32 SvtDynamicMenuOptions::m_nRefCount = 0;
-
-// constructor
+namespace {
+ // global
+ std::weak_ptr<SvtDynamicMenuOptions_Impl> g_pDynamicMenuOptions;
+}
SvtDynamicMenuOptions::SvtDynamicMenuOptions()
{
// Global access, must be guarded (multithreading!).
MutexGuard aGuard( GetOwnStaticMutex() );
- // Increase our refcount ...
- ++m_nRefCount;
- // ... and initialize our data container only if it not already exist!
- if( m_pDataContainer == nullptr )
+
+ m_pImpl = g_pDynamicMenuOptions.lock();
+ if( !m_pImpl )
{
- m_pDataContainer = new SvtDynamicMenuOptions_Impl;
+ m_pImpl = std::make_shared<SvtDynamicMenuOptions_Impl>();
+ g_pDynamicMenuOptions = m_pImpl;
ItemHolder1::holdConfigItem(E_DYNAMICMENUOPTIONS);
}
}
-// destructor
-
SvtDynamicMenuOptions::~SvtDynamicMenuOptions()
{
// Global access, must be guarded (multithreading!)
MutexGuard aGuard( GetOwnStaticMutex() );
- // Decrease our refcount.
- --m_nRefCount;
- // If last instance was deleted ...
- // we must destroy our static data container!
- if( m_nRefCount <= 0 )
- {
- delete m_pDataContainer;
- m_pDataContainer = nullptr;
- }
+
+ m_pImpl.reset();
}
// public method
@@ -611,7 +598,7 @@ SvtDynamicMenuOptions::~SvtDynamicMenuOptions()
Sequence< Sequence< PropertyValue > > SvtDynamicMenuOptions::GetMenu( EDynamicMenuType eMenu ) const
{
MutexGuard aGuard( GetOwnStaticMutex() );
- return m_pDataContainer->GetMenu( eMenu );
+ return m_pImpl->GetMenu( eMenu );
}
namespace