Use SolarMutexGuard directly

Change-Id: I5286db18d3d273f4678c9f332d5184b46e5bb720
This commit is contained in:
Stephan Bergmann
2014-03-17 18:28:40 +01:00
parent 60d14352f7
commit c5630fed3b
2 changed files with 12 additions and 62 deletions

View File

@@ -20,7 +20,6 @@
#include <accelerators/acceleratorcache.hxx> #include <accelerators/acceleratorcache.hxx>
#include <xml/acceleratorconfigurationreader.hxx> #include <xml/acceleratorconfigurationreader.hxx>
#include <threadhelp/guard.hxx>
#include <com/sun/star/container/ElementExistException.hpp> #include <com/sun/star/container/ElementExistException.hpp>
@@ -33,13 +32,11 @@ namespace framework
AcceleratorCache::AcceleratorCache() AcceleratorCache::AcceleratorCache()
: ThreadHelpBase(&Application::GetSolarMutex())
{ {
} }
AcceleratorCache::AcceleratorCache(const AcceleratorCache& rCopy) AcceleratorCache::AcceleratorCache(const AcceleratorCache& rCopy)
: ThreadHelpBase(&Application::GetSolarMutex())
{ {
m_lCommand2Keys = rCopy.m_lCommand2Keys; m_lCommand2Keys = rCopy.m_lCommand2Keys;
m_lKey2Commands = rCopy.m_lKey2Commands; m_lKey2Commands = rCopy.m_lKey2Commands;
@@ -55,14 +52,9 @@ AcceleratorCache::~AcceleratorCache()
void AcceleratorCache::takeOver(const AcceleratorCache& rCopy) void AcceleratorCache::takeOver(const AcceleratorCache& rCopy)
{ {
// SAFE -> ---------------------------------- SolarMutexGuard g;
Guard aWriteLock(m_aLock);
m_lCommand2Keys = rCopy.m_lCommand2Keys; m_lCommand2Keys = rCopy.m_lCommand2Keys;
m_lKey2Commands = rCopy.m_lKey2Commands; m_lKey2Commands = rCopy.m_lKey2Commands;
aWriteLock.unlock();
// <- SAFE ----------------------------------
} }
@@ -75,30 +67,22 @@ AcceleratorCache& AcceleratorCache::operator=(const AcceleratorCache& rCopy)
sal_Bool AcceleratorCache::hasKey(const css::awt::KeyEvent& aKey) const sal_Bool AcceleratorCache::hasKey(const css::awt::KeyEvent& aKey) const
{ {
// SAFE -> ---------------------------------- SolarMutexGuard g;
Guard aReadLock(m_aLock);
return (m_lKey2Commands.find(aKey) != m_lKey2Commands.end()); return (m_lKey2Commands.find(aKey) != m_lKey2Commands.end());
// <- SAFE ----------------------------------
} }
sal_Bool AcceleratorCache::hasCommand(const OUString& sCommand) const sal_Bool AcceleratorCache::hasCommand(const OUString& sCommand) const
{ {
// SAFE -> ---------------------------------- SolarMutexGuard g;
Guard aReadLock(m_aLock);
return (m_lCommand2Keys.find(sCommand) != m_lCommand2Keys.end()); return (m_lCommand2Keys.find(sCommand) != m_lCommand2Keys.end());
// <- SAFE ----------------------------------
} }
AcceleratorCache::TKeyList AcceleratorCache::getAllKeys() const AcceleratorCache::TKeyList AcceleratorCache::getAllKeys() const
{ {
SolarMutexGuard g;
TKeyList lKeys; TKeyList lKeys;
// SAFE -> ----------------------------------
Guard aReadLock(m_aLock);
lKeys.reserve(m_lKey2Commands.size()); lKeys.reserve(m_lKey2Commands.size());
TKey2Commands::const_iterator pIt; TKey2Commands::const_iterator pIt;
@@ -110,9 +94,6 @@ AcceleratorCache::TKeyList AcceleratorCache::getAllKeys() const
lKeys.push_back(pIt->first); lKeys.push_back(pIt->first);
} }
aReadLock.unlock();
// <- SAFE ----------------------------------
return lKeys; return lKeys;
} }
@@ -120,8 +101,7 @@ AcceleratorCache::TKeyList AcceleratorCache::getAllKeys() const
void AcceleratorCache::setKeyCommandPair(const css::awt::KeyEvent& aKey , void AcceleratorCache::setKeyCommandPair(const css::awt::KeyEvent& aKey ,
const OUString& sCommand) const OUString& sCommand)
{ {
// SAFE -> ---------------------------------- SolarMutexGuard g;
Guard aWriteLock(m_aLock);
// register command for the specified key // register command for the specified key
m_lKey2Commands[aKey] = sCommand; m_lKey2Commands[aKey] = sCommand;
@@ -129,56 +109,34 @@ void AcceleratorCache::setKeyCommandPair(const css::awt::KeyEvent& aKey ,
// update optimized structure to bind multiple keys to one command // update optimized structure to bind multiple keys to one command
TKeyList& rKeyList = m_lCommand2Keys[sCommand]; TKeyList& rKeyList = m_lCommand2Keys[sCommand];
rKeyList.push_back(aKey); rKeyList.push_back(aKey);
aWriteLock.unlock();
// <- SAFE ----------------------------------
} }
AcceleratorCache::TKeyList AcceleratorCache::getKeysByCommand(const OUString& sCommand) const AcceleratorCache::TKeyList AcceleratorCache::getKeysByCommand(const OUString& sCommand) const
{ {
TKeyList lKeys; SolarMutexGuard g;
// SAFE -> ----------------------------------
Guard aReadLock(m_aLock);
TCommand2Keys::const_iterator pCommand = m_lCommand2Keys.find(sCommand); TCommand2Keys::const_iterator pCommand = m_lCommand2Keys.find(sCommand);
if (pCommand == m_lCommand2Keys.end()) if (pCommand == m_lCommand2Keys.end())
throw css::container::NoSuchElementException( throw css::container::NoSuchElementException(
OUString(), css::uno::Reference< css::uno::XInterface >()); OUString(), css::uno::Reference< css::uno::XInterface >());
lKeys = pCommand->second; return pCommand->second;
aReadLock.unlock();
// <- SAFE ----------------------------------
return lKeys;
} }
OUString AcceleratorCache::getCommandByKey(const css::awt::KeyEvent& aKey) const OUString AcceleratorCache::getCommandByKey(const css::awt::KeyEvent& aKey) const
{ {
OUString sCommand; SolarMutexGuard g;
// SAFE -> ----------------------------------
Guard aReadLock(m_aLock);
TKey2Commands::const_iterator pKey = m_lKey2Commands.find(aKey); TKey2Commands::const_iterator pKey = m_lKey2Commands.find(aKey);
if (pKey == m_lKey2Commands.end()) if (pKey == m_lKey2Commands.end())
throw css::container::NoSuchElementException( throw css::container::NoSuchElementException(
OUString(), css::uno::Reference< css::uno::XInterface >()); OUString(), css::uno::Reference< css::uno::XInterface >());
sCommand = pKey->second; return pKey->second;
aReadLock.unlock();
// <- SAFE ----------------------------------
return sCommand;
} }
void AcceleratorCache::removeKey(const css::awt::KeyEvent& aKey) void AcceleratorCache::removeKey(const css::awt::KeyEvent& aKey)
{ {
// SAFE -> ---------------------------------- SolarMutexGuard g;
Guard aWriteLock(m_aLock);
// check if key exists // check if key exists
TKey2Commands::const_iterator pKey = m_lKey2Commands.find(aKey); TKey2Commands::const_iterator pKey = m_lKey2Commands.find(aKey);
@@ -196,16 +154,12 @@ void AcceleratorCache::removeKey(const css::awt::KeyEvent& aKey)
// remove key from optimized command list // remove key from optimized command list
m_lCommand2Keys.erase(sCommand); m_lCommand2Keys.erase(sCommand);
aWriteLock.unlock();
// <- SAFE ----------------------------------
} }
void AcceleratorCache::removeCommand(const OUString& sCommand) void AcceleratorCache::removeCommand(const OUString& sCommand)
{ {
// SAFE -> ---------------------------------- SolarMutexGuard g;
Guard aWriteLock(m_aLock);
const TKeyList& lKeys = getKeysByCommand(sCommand); const TKeyList& lKeys = getKeysByCommand(sCommand);
AcceleratorCache::TKeyList::const_iterator pKey ; AcceleratorCache::TKeyList::const_iterator pKey ;
@@ -217,9 +171,6 @@ void AcceleratorCache::removeCommand(const OUString& sCommand)
removeKey(rKey); removeKey(rKey);
} }
m_lCommand2Keys.erase(sCommand); m_lCommand2Keys.erase(sCommand);
aWriteLock.unlock();
// <- SAFE ----------------------------------
} }
} // namespace framework } // namespace framework

View File

@@ -20,7 +20,6 @@
#ifndef INCLUDED_FRAMEWORK_SOURCE_INC_ACCELERATORS_ACCELERATORCACHE_HXX #ifndef INCLUDED_FRAMEWORK_SOURCE_INC_ACCELERATORS_ACCELERATORCACHE_HXX
#define INCLUDED_FRAMEWORK_SOURCE_INC_ACCELERATORS_ACCELERATORCACHE_HXX #define INCLUDED_FRAMEWORK_SOURCE_INC_ACCELERATORS_ACCELERATORCACHE_HXX
#include <threadhelp/threadhelpbase.hxx>
#include <general.h> #include <general.h>
#include <stdtypes.h> #include <stdtypes.h>
@@ -44,7 +43,7 @@ namespace framework
copy-on-write ... How? Do the following: copy-on-write ... How? Do the following:
*/ */
class AcceleratorCache : public ThreadHelpBase // attention! Must be the first base class to guarentee right initialize lock ... class AcceleratorCache
{ {
// const, types // const, types