diff options
author | Caolán McNamara <caolanm@redhat.com> | 2014-10-24 11:39:02 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-10-24 13:43:09 +0100 |
commit | 5652f529b51436bf7bba8e9b4cb0fbab722f79a9 (patch) | |
tree | 91ee9e565ff7defd48fa6da35cf7caa31cdbb397 /scripting | |
parent | 03c870dfc6aa140354613b0c179fb7bec2e74a73 (diff) |
coverity#1237350 use our double-locking templates for this
Change-Id: I589468e9663ffd01a237a1684345985396bc4eac
Diffstat (limited to 'scripting')
-rw-r--r-- | scripting/source/provider/ActiveMSPList.cxx | 43 | ||||
-rw-r--r-- | scripting/source/provider/ActiveMSPList.hxx | 5 |
2 files changed, 25 insertions, 23 deletions
diff --git a/scripting/source/provider/ActiveMSPList.cxx b/scripting/source/provider/ActiveMSPList.cxx index 5bfbb39a474a..2df8ed325cdc 100644 --- a/scripting/source/provider/ActiveMSPList.cxx +++ b/scripting/source/provider/ActiveMSPList.cxx @@ -66,6 +66,26 @@ ActiveMSPList::createNewMSP( const uno::Any& context ) return msp; } +class NonDocMSPCreator +{ +public: + NonDocMSPCreator(ActiveMSPList *pList) + { + pList->createNonDocMSPs(); + } +}; + +namespace +{ + //thread-safe double-locked class to ensure createNonDocMSPs is called once + class theNonDocMSPCreator : public rtl::StaticWithArg<NonDocMSPCreator, ActiveMSPList*, theNonDocMSPCreator> {}; + + void ensureNonDocMSPs(ActiveMSPList *pList) + { + theNonDocMSPCreator::get(pList); + } +} + Reference< provider::XScriptProvider > ActiveMSPList::getMSPFromAnyContext( const Any& aContext ) { @@ -105,7 +125,7 @@ ActiveMSPList::getMSPFromAnyContext( const Any& aContext ) return msp; } - ensureNonDocMSPs(); + ensureNonDocMSPs(this); return m_hMsps[ shareDirString ]; } @@ -287,27 +307,6 @@ ActiveMSPList::createNonDocMSPs() m_hMsps[ bundledDirString ] = bundledMsp; } -void -ActiveMSPList::ensureNonDocMSPs() -{ - static bool created = false; - if ( created ) - { - return; - } - else - { - ::osl::MutexGuard guard( m_mutex ); - if ( created ) - { - return; - } - createNonDocMSPs(); - created = true; - } -} - - } // namespace func_provider /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/scripting/source/provider/ActiveMSPList.hxx b/scripting/source/provider/ActiveMSPList.hxx index a50b6e5d7b34..9b2e80329643 100644 --- a/scripting/source/provider/ActiveMSPList.hxx +++ b/scripting/source/provider/ActiveMSPList.hxx @@ -53,6 +53,8 @@ typedef ::boost::unordered_map< OUString, OUStringHash, ::std::equal_to< OUString > > Msp_hash; +class NonDocMSPCreator; + class ActiveMSPList : public ::cppu::WeakImplHelper1< css::lang::XEventListener > { @@ -88,8 +90,9 @@ private: return createNewMSP( css::uno::makeAny( context ) ); } - void ensureNonDocMSPs(); + friend class NonDocMSPCreator; void createNonDocMSPs(); + Msp_hash m_hMsps; ScriptComponent_map m_mScriptComponents; osl::Mutex m_mutex; |