ICU-8464 Remove dependency between LRUCache and mutex.
X-SVN-Rev: 34691
This commit is contained in:
parent
32fd3380c0
commit
9c65c145ff
@ -9,7 +9,6 @@
|
||||
*/
|
||||
|
||||
#include "lrucache.h"
|
||||
#include "mutex.h"
|
||||
#include "uhash.h"
|
||||
#include "cstring.h"
|
||||
|
||||
@ -120,7 +119,6 @@ UBool LRUCache::contains(const char *localeId) const {
|
||||
|
||||
|
||||
void LRUCache::_get(const char *localeId, SharedPtr<UObject>& ptr, UErrorCode &status) {
|
||||
Mutex lock(mutex);
|
||||
CacheEntry2 *entry = (CacheEntry2 *) uhash_get(localeIdToEntries, localeId);
|
||||
if (entry != NULL) {
|
||||
moveToMostRecent(entry);
|
||||
@ -172,12 +170,11 @@ void LRUCache::_get(const char *localeId, SharedPtr<UObject>& ptr, UErrorCode &s
|
||||
ptr = entry->cachedData;
|
||||
}
|
||||
|
||||
LRUCache::LRUCache(int32_t size, UMutex *mtx, UErrorCode &status) :
|
||||
LRUCache::LRUCache(int32_t size, UErrorCode &status) :
|
||||
mostRecentlyUsedMarker(NULL),
|
||||
leastRecentlyUsedMarker(NULL),
|
||||
localeIdToEntries(NULL),
|
||||
maxSize(size),
|
||||
mutex(mtx) {
|
||||
maxSize(size) {
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
|
@ -12,7 +12,6 @@
|
||||
#define __LRU_CACHE_H__
|
||||
|
||||
#include "unicode/uobject.h"
|
||||
#include "umutex.h"
|
||||
#include "sharedptr.h"
|
||||
|
||||
struct UHashtable;
|
||||
@ -40,7 +39,7 @@ class U_COMMON_API LRUCache : public UObject {
|
||||
virtual ~LRUCache();
|
||||
protected:
|
||||
virtual UObject *create(const char *localeId, UErrorCode &status)=0;
|
||||
LRUCache(int32_t maxSize, UMutex *mutex, UErrorCode &status);
|
||||
LRUCache(int32_t maxSize, UErrorCode &status);
|
||||
private:
|
||||
LRUCache();
|
||||
LRUCache(const LRUCache &other);
|
||||
@ -50,7 +49,6 @@ class U_COMMON_API LRUCache : public UObject {
|
||||
CacheEntry2 *leastRecentlyUsedMarker;
|
||||
UHashtable *localeIdToEntries;
|
||||
int32_t maxSize;
|
||||
UMutex *mutex;
|
||||
|
||||
void moveToMostRecent(CacheEntry2 *cacheEntry);
|
||||
UBool init(const char *localeId, CacheEntry2 *cacheEntry);
|
||||
@ -63,10 +61,9 @@ class U_COMMON_API SimpleLRUCache : public LRUCache {
|
||||
public:
|
||||
SimpleLRUCache(
|
||||
int32_t maxSize,
|
||||
UMutex *mutex,
|
||||
CreateFunc cf,
|
||||
UErrorCode &status) :
|
||||
LRUCache(maxSize, mutex, status), createFunc(cf) {
|
||||
LRUCache(maxSize, status), createFunc(cf) {
|
||||
}
|
||||
virtual ~SimpleLRUCache();
|
||||
protected:
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "cstring.h"
|
||||
#include "plurrule_impl.h"
|
||||
#include "ucln_in.h"
|
||||
#include "mutex.h"
|
||||
|
||||
#include "sharedptr.h"
|
||||
|
||||
@ -590,7 +591,7 @@ static UObject *U_CALLCONV createData(const char *localeId, UErrorCode &status)
|
||||
static void U_CALLCONV cacheInit(UErrorCode &status) {
|
||||
U_ASSERT(gCache == NULL);
|
||||
ucln_i18n_registerCleanup(UCLN_I18N_RELDATEFMT, reldatefmt_cleanup);
|
||||
gCache = new SimpleLRUCache(100, &gCacheMutex, &createData, status);
|
||||
gCache = new SimpleLRUCache(100, &createData, status);
|
||||
if (U_FAILURE(status)) {
|
||||
delete gCache;
|
||||
gCache = NULL;
|
||||
@ -602,6 +603,7 @@ static void getFromCache(const char *locale, SharedPtr<RelativeDateTimeData>& pt
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
Mutex lock(&gCacheMutex);
|
||||
gCache->get(locale, ptr, status);
|
||||
}
|
||||
|
||||
|
@ -317,9 +317,7 @@
|
||||
<ClCompile Include="plurfmts.cpp" />
|
||||
<ClCompile Include="plurults.cpp" />
|
||||
<ClCompile Include="pptest.cpp" />
|
||||
<ClCompile Include="reldatefmttest.cpp">
|
||||
<DisableLanguageExtensions>false</DisableLanguageExtensions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="reldatefmttest.cpp" />
|
||||
<ClCompile Include="sdtfmtts.cpp" />
|
||||
<ClCompile Include="selfmts.cpp" />
|
||||
<ClCompile Include="tchcfmt.cpp" />
|
||||
|
@ -11,9 +11,6 @@
|
||||
#include "cstring.h"
|
||||
#include "intltest.h"
|
||||
#include "lrucache.h"
|
||||
#include "umutex.h"
|
||||
|
||||
static UMutex gMutex = U_MUTEX_INITIALIZER;
|
||||
|
||||
class CopyOnWriteForTesting : public UObject {
|
||||
public:
|
||||
@ -39,7 +36,7 @@ private:
|
||||
class LRUCacheForTesting : public LRUCache {
|
||||
public:
|
||||
LRUCacheForTesting(
|
||||
int32_t maxSize, UMutex *mutex,
|
||||
int32_t maxSize,
|
||||
const UnicodeString &dfs, UErrorCode &status);
|
||||
virtual ~LRUCacheForTesting() {
|
||||
}
|
||||
@ -50,9 +47,9 @@ private:
|
||||
};
|
||||
|
||||
LRUCacheForTesting::LRUCacheForTesting(
|
||||
int32_t maxSize, UMutex *mutex,
|
||||
int32_t maxSize,
|
||||
const UnicodeString &dfs, UErrorCode &status) :
|
||||
LRUCache(maxSize, mutex, status), defaultFormatStr() {
|
||||
LRUCache(maxSize, status), defaultFormatStr() {
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
@ -104,7 +101,7 @@ void LRUCacheTest::runIndexedTest(int32_t index, UBool exec, const char* &name,
|
||||
|
||||
void LRUCacheTest::TestSharedPointer() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LRUCacheForTesting cache(3, &gMutex, "little", status);
|
||||
LRUCacheForTesting cache(3, "little", status);
|
||||
SharedPtr<CopyOnWriteForTesting> ptr;
|
||||
cache.get("boo", ptr, status);
|
||||
verifySharedPointer(ptr, "boo", "little");
|
||||
@ -130,12 +127,12 @@ void LRUCacheTest::TestSharedPointer() {
|
||||
|
||||
void LRUCacheTest::TestErrorCallingConstructor() {
|
||||
UErrorCode status = U_MEMORY_ALLOCATION_ERROR;
|
||||
LRUCacheForTesting cache(3, &gMutex, "little", status);
|
||||
LRUCacheForTesting cache(3, "little", status);
|
||||
}
|
||||
|
||||
void LRUCacheTest::TestLRUCache() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LRUCacheForTesting cache(3, &gMutex, "little", status);
|
||||
LRUCacheForTesting cache(3, "little", status);
|
||||
SharedPtr<CopyOnWriteForTesting> ptr1;
|
||||
SharedPtr<CopyOnWriteForTesting> ptr2;
|
||||
SharedPtr<CopyOnWriteForTesting> ptr3;
|
||||
@ -224,7 +221,7 @@ void LRUCacheTest::TestLRUCache() {
|
||||
|
||||
void LRUCacheTest::TestLRUCacheError() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LRUCacheForTesting cache(3, &gMutex, "little", status);
|
||||
LRUCacheForTesting cache(3, "little", status);
|
||||
SharedPtr<CopyOnWriteForTesting> ptr1;
|
||||
cache.get("error", ptr1, status);
|
||||
if (status != U_ILLEGAL_ARGUMENT_ERROR) {
|
||||
|
Loading…
Reference in New Issue
Block a user