diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-05-17 16:15:49 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-05-20 15:23:08 +0100 |
commit | e77040b6ef545032c58ee863243217fd4889eb09 (patch) | |
tree | 3d90fea1e6caf04e72af429ce3753dd17541b0a4 /sfx2 | |
parent | d6c5f4f3d5c3a92ce94c0d25649d67ffe7faad4e (diff) |
valgrind: use non-leaky singleton here
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/appl/sfxpicklist.cxx | 35 | ||||
-rw-r--r-- | sfx2/source/inc/sfxpicklist.hxx | 3 |
2 files changed, 14 insertions, 24 deletions
diff --git a/sfx2/source/appl/sfxpicklist.cxx b/sfx2/source/appl/sfxpicklist.cxx index 62ca967c03..dfcc03c9d3 100644 --- a/sfx2/source/appl/sfxpicklist.cxx +++ b/sfx2/source/appl/sfxpicklist.cxx @@ -58,6 +58,8 @@ #include "objshimp.hxx" #include <sfx2/docfilt.hxx> +#include <rtl/instance.hxx> + #include <algorithm> // ---------------------------------------------------------------------------- @@ -68,7 +70,6 @@ using namespace ::com::sun::star::util; // ---------------------------------------------------------------------------- -osl::Mutex* SfxPickList::pMutex = 0; SfxPickList* SfxPickList::pUniqueInstance = 0; // ---------------------------------------------------------------------------- @@ -87,20 +88,6 @@ class StringLength : public ::cppu::WeakImplHelper1< XStringWidth > } }; -// ---------------------------------------------------------------------------- - -osl::Mutex* SfxPickList::GetOrCreateMutex() -{ - if ( !pMutex ) - { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - if ( !pMutex ) - pMutex = new osl::Mutex; - } - - return pMutex; -} - void SfxPickList::CreatePicklistMenuTitle( Menu* pMenu, sal_uInt16 nItemId, const String& aURLString, sal_uInt32 nNo ) { String aPickEntry; @@ -159,9 +146,15 @@ void SfxPickList::CreatePicklistMenuTitle( Menu* pMenu, sal_uInt16 nItemId, cons pMenu->SetAccessibleName( nItemId, aAccessibleName ); } +namespace +{ + class thePickListMutex + : public rtl::Static<osl::Mutex, thePickListMutex> {}; +} + void SfxPickList::RemovePickListEntries() { - ::osl::MutexGuard aGuard( GetOrCreateMutex() ); + ::osl::MutexGuard aGuard( thePickListMutex::get() ); for ( sal_uInt32 i = 0; i < m_aPicklistVector.size(); i++ ) delete m_aPicklistVector[i]; m_aPicklistVector.clear(); @@ -181,7 +174,7 @@ SfxPickList* SfxPickList::GetOrCreate( const sal_uInt32 nMenuSize ) { if ( !pUniqueInstance ) { - ::osl::MutexGuard aGuard( GetOrCreateMutex() ); + ::osl::MutexGuard aGuard( thePickListMutex::get() ); if ( !pUniqueInstance ) pUniqueInstance = new SfxPickList( nMenuSize ); } @@ -191,13 +184,13 @@ SfxPickList* SfxPickList::GetOrCreate( const sal_uInt32 nMenuSize ) SfxPickList* SfxPickList::Get() { - ::osl::MutexGuard aGuard( GetOrCreateMutex() ); + ::osl::MutexGuard aGuard( thePickListMutex::get() ); return pUniqueInstance; } void SfxPickList::Delete() { - ::osl::MutexGuard aGuard( GetOrCreateMutex() ); + ::osl::MutexGuard aGuard( thePickListMutex::get() ); DELETEZ( pUniqueInstance ); } @@ -267,7 +260,7 @@ void SfxPickList::CreateMenuEntries( Menu* pMenu ) { static sal_Bool bPickListMenuInitializing = sal_False; - ::osl::MutexGuard aGuard( GetOrCreateMutex() ); + ::osl::MutexGuard aGuard( thePickListMutex::get() ); if ( bPickListMenuInitializing ) // method is not reentrant! return; @@ -300,7 +293,7 @@ void SfxPickList::CreateMenuEntries( Menu* pMenu ) void SfxPickList::ExecuteEntry( sal_uInt32 nIndex ) { - ::osl::ClearableMutexGuard aGuard( GetOrCreateMutex() ); + ::osl::ClearableMutexGuard aGuard( thePickListMutex::get() ); PickListEntry *pPick = SfxPickList::Get()->GetPickListEntry( nIndex ); diff --git a/sfx2/source/inc/sfxpicklist.hxx b/sfx2/source/inc/sfxpicklist.hxx index 0f906699e7..28845aa97b 100644 --- a/sfx2/source/inc/sfxpicklist.hxx +++ b/sfx2/source/inc/sfxpicklist.hxx @@ -53,7 +53,6 @@ class SfxPickList : public SfxListener }; static SfxPickList* pUniqueInstance; - static osl::Mutex* pMutex; std::vector< PickListEntry* > m_aPicklistVector; sal_uInt32 m_nAllowedMenuSize; @@ -62,8 +61,6 @@ class SfxPickList : public SfxListener SfxPickList( sal_uInt32 nMenuSize ); ~SfxPickList(); - static osl::Mutex* GetOrCreateMutex(); - void CreatePicklistMenuTitle( Menu* pMenu, sal_uInt16 nItemId, const String& aURL, sal_uInt32 nNo ); PickListEntry* GetPickListEntry( sal_uInt32 nIndex ); void CreatePickListEntries(); |