Use an osl::Mutex directly
Change-Id: If8ff4fc256e530f6b79cc97cf1f47880c93864bf
This commit is contained in:
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include <accelerators/storageholder.hxx>
|
#include <accelerators/storageholder.hxx>
|
||||||
|
|
||||||
#include <threadhelp/guard.hxx>
|
|
||||||
#include <services.h>
|
#include <services.h>
|
||||||
|
|
||||||
#include <com/sun/star/container/NoSuchElementException.hpp>
|
#include <com/sun/star/container/NoSuchElementException.hpp>
|
||||||
@@ -49,7 +48,6 @@ namespace framework
|
|||||||
|
|
||||||
|
|
||||||
StorageHolder::StorageHolder()
|
StorageHolder::StorageHolder()
|
||||||
: ThreadHelpBase( )
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,9 +61,7 @@ StorageHolder::~StorageHolder()
|
|||||||
|
|
||||||
void StorageHolder::forgetCachedStorages()
|
void StorageHolder::forgetCachedStorages()
|
||||||
{
|
{
|
||||||
// SAFE -> ----------------------------------
|
osl::MutexGuard g(m_mutex);
|
||||||
Guard aWriteLock(m_aLock);
|
|
||||||
|
|
||||||
TPath2StorageInfo::iterator pIt;
|
TPath2StorageInfo::iterator pIt;
|
||||||
for ( pIt = m_lStorages.begin();
|
for ( pIt = m_lStorages.begin();
|
||||||
pIt != m_lStorages.end() ;
|
pIt != m_lStorages.end() ;
|
||||||
@@ -76,28 +72,20 @@ void StorageHolder::forgetCachedStorages()
|
|||||||
rInfo.Storage.clear();
|
rInfo.Storage.clear();
|
||||||
}
|
}
|
||||||
m_lStorages.clear();
|
m_lStorages.clear();
|
||||||
|
|
||||||
aWriteLock.unlock();
|
|
||||||
// <- SAFE ----------------------------------
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void StorageHolder::setRootStorage(const css::uno::Reference< css::embed::XStorage >& xRoot)
|
void StorageHolder::setRootStorage(const css::uno::Reference< css::embed::XStorage >& xRoot)
|
||||||
{
|
{
|
||||||
// SAFE -> ----------------------------------
|
osl::MutexGuard g(m_mutex);
|
||||||
Guard aWriteLock(m_aLock);
|
|
||||||
m_xRoot = xRoot;
|
m_xRoot = xRoot;
|
||||||
aWriteLock.unlock();
|
|
||||||
// <- SAFE ----------------------------------
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
css::uno::Reference< css::embed::XStorage > StorageHolder::getRootStorage() const
|
css::uno::Reference< css::embed::XStorage > StorageHolder::getRootStorage() const
|
||||||
{
|
{
|
||||||
// SAFE -> ----------------------------------
|
osl::MutexGuard g(m_mutex);
|
||||||
Guard aReadLock(m_aLock);
|
|
||||||
return m_xRoot;
|
return m_xRoot;
|
||||||
// <- SAFE ----------------------------------
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -108,9 +96,9 @@ css::uno::Reference< css::embed::XStorage > StorageHolder::openPath(const OUStri
|
|||||||
OUStringList lFolders = StorageHolder::impl_st_parsePath(sNormedPath);
|
OUStringList lFolders = StorageHolder::impl_st_parsePath(sNormedPath);
|
||||||
|
|
||||||
// SAFE -> ----------------------------------
|
// SAFE -> ----------------------------------
|
||||||
Guard aReadLock(m_aLock);
|
osl::ResettableMutexGuard aReadLock(m_mutex);
|
||||||
css::uno::Reference< css::embed::XStorage > xParent = m_xRoot;
|
css::uno::Reference< css::embed::XStorage > xParent = m_xRoot;
|
||||||
aReadLock.unlock();
|
aReadLock.clear();
|
||||||
// <- SAFE ----------------------------------
|
// <- SAFE ----------------------------------
|
||||||
|
|
||||||
css::uno::Reference< css::embed::XStorage > xChild ;
|
css::uno::Reference< css::embed::XStorage > xChild ;
|
||||||
@@ -127,7 +115,7 @@ css::uno::Reference< css::embed::XStorage > StorageHolder::openPath(const OUStri
|
|||||||
sCheckPath += PATH_SEPARATOR;
|
sCheckPath += PATH_SEPARATOR;
|
||||||
|
|
||||||
// SAFE -> ------------------------------
|
// SAFE -> ------------------------------
|
||||||
aReadLock.lock();
|
aReadLock.reset();
|
||||||
|
|
||||||
// If we found an already open storage ... we must increase
|
// If we found an already open storage ... we must increase
|
||||||
// its use count. Otherwhise it will may be closed to early :-)
|
// its use count. Otherwhise it will may be closed to early :-)
|
||||||
@@ -138,10 +126,13 @@ css::uno::Reference< css::embed::XStorage > StorageHolder::openPath(const OUStri
|
|||||||
pInfo = &(pCheck->second);
|
pInfo = &(pCheck->second);
|
||||||
++(pInfo->UseCount);
|
++(pInfo->UseCount);
|
||||||
xChild = pInfo->Storage;
|
xChild = pInfo->Storage;
|
||||||
|
|
||||||
|
aReadLock.clear();
|
||||||
|
// <- SAFE ------------------------------
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
aReadLock.unlock();
|
aReadLock.clear();
|
||||||
// <- SAFE ------------------------------
|
// <- SAFE ------------------------------
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -165,13 +156,10 @@ css::uno::Reference< css::embed::XStorage > StorageHolder::openPath(const OUStri
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SAFE -> ------------------------------
|
osl::MutexGuard g(m_mutex);
|
||||||
Guard aWriteLock(m_aLock);
|
|
||||||
pInfo = &(m_lStorages[sCheckPath]);
|
pInfo = &(m_lStorages[sCheckPath]);
|
||||||
pInfo->Storage = xChild;
|
pInfo->Storage = xChild;
|
||||||
pInfo->UseCount = 1;
|
pInfo->UseCount = 1;
|
||||||
aWriteLock.unlock();
|
|
||||||
// <- SAFE ------------------------------
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xParent = xChild;
|
xParent = xChild;
|
||||||
@@ -195,8 +183,7 @@ StorageHolder::TStorageList StorageHolder::getAllPathStorages(const OUString& sP
|
|||||||
OUString sRelPath ;
|
OUString sRelPath ;
|
||||||
OUStringList::const_iterator pIt ;
|
OUStringList::const_iterator pIt ;
|
||||||
|
|
||||||
// SAFE -> ----------------------------------
|
osl::MutexGuard g(m_mutex);
|
||||||
Guard aReadLock(m_aLock);
|
|
||||||
|
|
||||||
for ( pIt = lFolders.begin();
|
for ( pIt = lFolders.begin();
|
||||||
pIt != lFolders.end() ;
|
pIt != lFolders.end() ;
|
||||||
@@ -223,9 +210,6 @@ StorageHolder::TStorageList StorageHolder::getAllPathStorages(const OUString& sP
|
|||||||
sRelPath += PATH_SEPARATOR;
|
sRelPath += PATH_SEPARATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
aReadLock.unlock();
|
|
||||||
// <- SAFE ----------------------------------
|
|
||||||
|
|
||||||
return lStoragesOfPath;
|
return lStoragesOfPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,9 +231,9 @@ void StorageHolder::commitPath(const OUString& sPath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SAFE -> ------------------------------
|
// SAFE -> ------------------------------
|
||||||
Guard aReadLock(m_aLock);
|
osl::ClearableMutexGuard aReadLock(m_mutex);
|
||||||
xCommit = css::uno::Reference< css::embed::XTransactedObject >(m_xRoot, css::uno::UNO_QUERY);
|
xCommit = css::uno::Reference< css::embed::XTransactedObject >(m_xRoot, css::uno::UNO_QUERY);
|
||||||
aReadLock.unlock();
|
aReadLock.clear();
|
||||||
// <- SAFE ------------------------------
|
// <- SAFE ------------------------------
|
||||||
|
|
||||||
if (xCommit.is())
|
if (xCommit.is())
|
||||||
@@ -280,8 +264,7 @@ void StorageHolder::closePath(const OUString& rPath)
|
|||||||
sParentPath = sCurrentRelPath;
|
sParentPath = sCurrentRelPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SAFE -> ------------------------------
|
osl::MutexGuard g(m_mutex);
|
||||||
Guard aReadLock(m_aLock);
|
|
||||||
|
|
||||||
OUStringList::reverse_iterator pIt2;
|
OUStringList::reverse_iterator pIt2;
|
||||||
for ( pIt2 = lFolders.rbegin();
|
for ( pIt2 = lFolders.rbegin();
|
||||||
@@ -301,9 +284,6 @@ void StorageHolder::closePath(const OUString& rPath)
|
|||||||
m_lStorages.erase(pPath);
|
m_lStorages.erase(pPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
aReadLock.unlock();
|
|
||||||
// <- SAFE ------------------------------
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -311,8 +291,7 @@ void StorageHolder::notifyPath(const OUString& sPath)
|
|||||||
{
|
{
|
||||||
OUString sNormedPath = StorageHolder::impl_st_normPath(sPath);
|
OUString sNormedPath = StorageHolder::impl_st_normPath(sPath);
|
||||||
|
|
||||||
// SAFE -> ------------------------------
|
osl::MutexGuard g(m_mutex);
|
||||||
Guard aReadLock(m_aLock);
|
|
||||||
|
|
||||||
TPath2StorageInfo::iterator pIt1 = m_lStorages.find(sNormedPath);
|
TPath2StorageInfo::iterator pIt1 = m_lStorages.find(sNormedPath);
|
||||||
if (pIt1 == m_lStorages.end())
|
if (pIt1 == m_lStorages.end())
|
||||||
@@ -328,9 +307,6 @@ void StorageHolder::notifyPath(const OUString& sPath)
|
|||||||
if (pListener)
|
if (pListener)
|
||||||
pListener->changesOccurred(sNormedPath);
|
pListener->changesOccurred(sNormedPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
aReadLock.unlock();
|
|
||||||
// <- SAFE ------------------------------
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -339,8 +315,7 @@ void StorageHolder::addStorageListener( IStorageListener* pListener,
|
|||||||
{
|
{
|
||||||
OUString sNormedPath = StorageHolder::impl_st_normPath(sPath);
|
OUString sNormedPath = StorageHolder::impl_st_normPath(sPath);
|
||||||
|
|
||||||
// SAFE -> ------------------------------
|
osl::MutexGuard g(m_mutex);
|
||||||
Guard aReadLock(m_aLock);
|
|
||||||
|
|
||||||
TPath2StorageInfo::iterator pIt1 = m_lStorages.find(sNormedPath);
|
TPath2StorageInfo::iterator pIt1 = m_lStorages.find(sNormedPath);
|
||||||
if (pIt1 == m_lStorages.end())
|
if (pIt1 == m_lStorages.end())
|
||||||
@@ -350,9 +325,6 @@ void StorageHolder::addStorageListener( IStorageListener* pListener,
|
|||||||
TStorageListenerList::iterator pIt2 = ::std::find(rInfo.Listener.begin(), rInfo.Listener.end(), pListener);
|
TStorageListenerList::iterator pIt2 = ::std::find(rInfo.Listener.begin(), rInfo.Listener.end(), pListener);
|
||||||
if (pIt2 == rInfo.Listener.end())
|
if (pIt2 == rInfo.Listener.end())
|
||||||
rInfo.Listener.push_back(pListener);
|
rInfo.Listener.push_back(pListener);
|
||||||
|
|
||||||
aReadLock.unlock();
|
|
||||||
// <- SAFE ------------------------------
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -361,8 +333,7 @@ void StorageHolder::removeStorageListener( IStorageListener* pListener,
|
|||||||
{
|
{
|
||||||
OUString sNormedPath = StorageHolder::impl_st_normPath(sPath);
|
OUString sNormedPath = StorageHolder::impl_st_normPath(sPath);
|
||||||
|
|
||||||
// SAFE -> ------------------------------
|
osl::MutexGuard g(m_mutex);
|
||||||
Guard aReadLock(m_aLock);
|
|
||||||
|
|
||||||
TPath2StorageInfo::iterator pIt1 = m_lStorages.find(sNormedPath);
|
TPath2StorageInfo::iterator pIt1 = m_lStorages.find(sNormedPath);
|
||||||
if (pIt1 == m_lStorages.end())
|
if (pIt1 == m_lStorages.end())
|
||||||
@@ -372,16 +343,12 @@ void StorageHolder::removeStorageListener( IStorageListener* pListener,
|
|||||||
TStorageListenerList::iterator pIt2 = ::std::find(rInfo.Listener.begin(), rInfo.Listener.end(), pListener);
|
TStorageListenerList::iterator pIt2 = ::std::find(rInfo.Listener.begin(), rInfo.Listener.end(), pListener);
|
||||||
if (pIt2 != rInfo.Listener.end())
|
if (pIt2 != rInfo.Listener.end())
|
||||||
rInfo.Listener.erase(pIt2);
|
rInfo.Listener.erase(pIt2);
|
||||||
|
|
||||||
aReadLock.unlock();
|
|
||||||
// <- SAFE ------------------------------
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
OUString StorageHolder::getPathOfStorage(const css::uno::Reference< css::embed::XStorage >& xStorage)
|
OUString StorageHolder::getPathOfStorage(const css::uno::Reference< css::embed::XStorage >& xStorage)
|
||||||
{
|
{
|
||||||
// SAFE -> ------------------------------
|
osl::MutexGuard g(m_mutex);
|
||||||
Guard aReadLock(m_aLock);
|
|
||||||
|
|
||||||
TPath2StorageInfo::const_iterator pIt;
|
TPath2StorageInfo::const_iterator pIt;
|
||||||
for ( pIt = m_lStorages.begin();
|
for ( pIt = m_lStorages.begin();
|
||||||
@@ -397,8 +364,6 @@ OUString StorageHolder::getPathOfStorage(const css::uno::Reference< css::embed::
|
|||||||
return OUString();
|
return OUString();
|
||||||
|
|
||||||
return pIt->first;
|
return pIt->first;
|
||||||
|
|
||||||
// <- SAFE ------------------------------
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -425,7 +390,7 @@ css::uno::Reference< css::embed::XStorage > StorageHolder::getParentStorage(cons
|
|||||||
return css::uno::Reference< css::embed::XStorage >();
|
return css::uno::Reference< css::embed::XStorage >();
|
||||||
|
|
||||||
// SAFE -> ----------------------------------
|
// SAFE -> ----------------------------------
|
||||||
Guard aReadLock(m_aLock);
|
osl::ClearableMutexGuard aReadLock(m_mutex);
|
||||||
|
|
||||||
// b)
|
// b)
|
||||||
if (c < 2)
|
if (c < 2)
|
||||||
@@ -444,7 +409,7 @@ css::uno::Reference< css::embed::XStorage > StorageHolder::getParentStorage(cons
|
|||||||
if (pParent != m_lStorages.end())
|
if (pParent != m_lStorages.end())
|
||||||
return pParent->second.Storage;
|
return pParent->second.Storage;
|
||||||
|
|
||||||
aReadLock.unlock();
|
aReadLock.clear();
|
||||||
// <- SAFE ----------------------------------
|
// <- SAFE ----------------------------------
|
||||||
|
|
||||||
// ?
|
// ?
|
||||||
@@ -455,14 +420,9 @@ css::uno::Reference< css::embed::XStorage > StorageHolder::getParentStorage(cons
|
|||||||
|
|
||||||
void StorageHolder::operator=(const StorageHolder& rCopy)
|
void StorageHolder::operator=(const StorageHolder& rCopy)
|
||||||
{
|
{
|
||||||
// SAFE -> ----------------------------------
|
osl::MutexGuard g(m_mutex);
|
||||||
Guard aWriteLock(m_aLock);
|
|
||||||
|
|
||||||
m_xRoot = rCopy.m_xRoot;
|
m_xRoot = rCopy.m_xRoot;
|
||||||
m_lStorages = rCopy.m_lStorages;
|
m_lStorages = rCopy.m_lStorages;
|
||||||
|
|
||||||
aWriteLock.unlock();
|
|
||||||
// <- SAFE ----------------------------------
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -21,7 +21,6 @@
|
|||||||
#define INCLUDED_FRAMEWORK_SOURCE_INC_ACCELERATORS_STORAGEHOLDER_HXX
|
#define INCLUDED_FRAMEWORK_SOURCE_INC_ACCELERATORS_STORAGEHOLDER_HXX
|
||||||
|
|
||||||
#include <accelerators/istoragelistener.hxx>
|
#include <accelerators/istoragelistener.hxx>
|
||||||
#include <threadhelp/threadhelpbase.hxx>
|
|
||||||
#include <general.h>
|
#include <general.h>
|
||||||
#include <stdtypes.h>
|
#include <stdtypes.h>
|
||||||
|
|
||||||
@@ -36,7 +35,7 @@ namespace framework
|
|||||||
/**
|
/**
|
||||||
TODO document me
|
TODO document me
|
||||||
*/
|
*/
|
||||||
class StorageHolder : private ThreadHelpBase // attention! Must be the first base class to guarentee right initialize lock ...
|
class StorageHolder
|
||||||
{
|
{
|
||||||
|
|
||||||
// types
|
// types
|
||||||
@@ -68,6 +67,7 @@ class StorageHolder : private ThreadHelpBase // attention! Must be the first bas
|
|||||||
|
|
||||||
// member
|
// member
|
||||||
private:
|
private:
|
||||||
|
mutable osl::Mutex m_mutex;
|
||||||
|
|
||||||
/** @short TODO */
|
/** @short TODO */
|
||||||
css::uno::Reference< css::embed::XStorage > m_xRoot;
|
css::uno::Reference< css::embed::XStorage > m_xRoot;
|
||||||
|
Reference in New Issue
Block a user