Add mutex to guard the shared string pool content.
Change-Id: I0eb97d0fbeaefd8a1c86d240ed8bd7f208fb662e
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
#define INCLUDED_SVL_SHAREDSTRINGPOOL_HXX
|
#define INCLUDED_SVL_SHAREDSTRINGPOOL_HXX
|
||||||
|
|
||||||
#include "svl/sharedstring.hxx"
|
#include "svl/sharedstring.hxx"
|
||||||
|
#include "osl/mutex.hxx"
|
||||||
|
|
||||||
#include <boost/unordered_map.hpp>
|
#include <boost/unordered_map.hpp>
|
||||||
#include <boost/unordered_set.hpp>
|
#include <boost/unordered_set.hpp>
|
||||||
@@ -30,6 +31,7 @@ class SVL_DLLPUBLIC SharedStringPool
|
|||||||
typedef std::pair<StrHashType::iterator, bool> InsertResultType;
|
typedef std::pair<StrHashType::iterator, bool> InsertResultType;
|
||||||
typedef boost::unordered_map<const rtl_uString*, OUString> StrStoreType;
|
typedef boost::unordered_map<const rtl_uString*, OUString> StrStoreType;
|
||||||
|
|
||||||
|
mutable osl::Mutex maMutex;
|
||||||
StrHashType maStrPool;
|
StrHashType maStrPool;
|
||||||
StrHashType maStrPoolUpper;
|
StrHashType maStrPoolUpper;
|
||||||
StrStoreType maStrStore;
|
StrStoreType maStrStore;
|
||||||
|
@@ -17,6 +17,8 @@ SharedStringPool::SharedStringPool( const CharClass* pCharClass ) : mpCharClass(
|
|||||||
|
|
||||||
SharedString SharedStringPool::intern( const OUString& rStr )
|
SharedString SharedStringPool::intern( const OUString& rStr )
|
||||||
{
|
{
|
||||||
|
osl::MutexGuard aGuard(&maMutex);
|
||||||
|
|
||||||
InsertResultType aRes = findOrInsert(maStrPool, rStr);
|
InsertResultType aRes = findOrInsert(maStrPool, rStr);
|
||||||
if (aRes.first == maStrPool.end())
|
if (aRes.first == maStrPool.end())
|
||||||
// Insertion failed.
|
// Insertion failed.
|
||||||
@@ -63,6 +65,8 @@ inline sal_Int32 getRefCount( const rtl_uString* p )
|
|||||||
|
|
||||||
void SharedStringPool::purge()
|
void SharedStringPool::purge()
|
||||||
{
|
{
|
||||||
|
osl::MutexGuard aGuard(&maMutex);
|
||||||
|
|
||||||
StrHashType aNewStrPool;
|
StrHashType aNewStrPool;
|
||||||
StrHashType::iterator it = maStrPool.begin(), itEnd = maStrPool.end();
|
StrHashType::iterator it = maStrPool.begin(), itEnd = maStrPool.end();
|
||||||
for (; it != itEnd; ++it)
|
for (; it != itEnd; ++it)
|
||||||
@@ -98,11 +102,13 @@ void SharedStringPool::purge()
|
|||||||
|
|
||||||
size_t SharedStringPool::getCount() const
|
size_t SharedStringPool::getCount() const
|
||||||
{
|
{
|
||||||
|
osl::MutexGuard aGuard(&maMutex);
|
||||||
return maStrPool.size();
|
return maStrPool.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t SharedStringPool::getCountIgnoreCase() const
|
size_t SharedStringPool::getCountIgnoreCase() const
|
||||||
{
|
{
|
||||||
|
osl::MutexGuard aGuard(&maMutex);
|
||||||
return maStrPoolUpper.size();
|
return maStrPoolUpper.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user