summaryrefslogtreecommitdiff
path: root/deps/icu-small/source/common/unifiedcache.cpp
diff options
context:
space:
mode:
authorAlbert Wang <git@albertyw.com>2019-11-02 18:08:46 -0700
committerRichard Lau <riclau@uk.ibm.com>2019-12-05 20:39:20 -0500
commit418dd68b611cce7e916dae82c75cb3d63b3c43a6 (patch)
tree0ed206d2abae637584d4f5690a17b4ab4dd46d39 /deps/icu-small/source/common/unifiedcache.cpp
parent6c40cb2aca89df4c7c0e3923d93024734dd49f2d (diff)
downloadandroid-node-v8-418dd68b611cce7e916dae82c75cb3d63b3c43a6.tar.gz
android-node-v8-418dd68b611cce7e916dae82c75cb3d63b3c43a6.tar.bz2
android-node-v8-418dd68b611cce7e916dae82c75cb3d63b3c43a6.zip
tools: update icu to 65.1
Update the version of the bundled ICU (deps/icu-small) to ICU version 65.2. Fixes: https://github.com/nodejs/node/issues/30211 Fixes: https://github.com/nodejs/node/issues/29540 PR-URL: https://github.com/nodejs/node/pull/30232 Reviewed-By: Steven R Loomis <srloomis@us.ibm.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
Diffstat (limited to 'deps/icu-small/source/common/unifiedcache.cpp')
-rw-r--r--deps/icu-small/source/common/unifiedcache.cpp51
1 files changed, 24 insertions, 27 deletions
diff --git a/deps/icu-small/source/common/unifiedcache.cpp b/deps/icu-small/source/common/unifiedcache.cpp
index 641f4ec659..f2dd916559 100644
--- a/deps/icu-small/source/common/unifiedcache.cpp
+++ b/deps/icu-small/source/common/unifiedcache.cpp
@@ -13,22 +13,15 @@
#include "unifiedcache.h"
#include <algorithm> // For std::max()
+#include <mutex>
-#include "mutex.h"
#include "uassert.h"
#include "uhash.h"
#include "ucln_cmn.h"
-#include "umutex.h"
static icu::UnifiedCache *gCache = NULL;
-static icu::UMutex *gCacheMutex() {
- static icu::UMutex m = U_MUTEX_INITIALIZER;
- return &m;
-}
-static icu::UConditionVar *gInProgressValueAddedCond() {
- static icu::UConditionVar cv = U_CONDITION_INITIALIZER;
- return &cv;
-}
+static std::mutex *gCacheMutex = nullptr;
+static std::condition_variable *gInProgressValueAddedCond;
static icu::UInitOnce gCacheInitOnce = U_INITONCE_INITIALIZER;
static const int32_t MAX_EVICT_ITERATIONS = 10;
@@ -39,10 +32,12 @@ static const int32_t DEFAULT_PERCENTAGE_OF_IN_USE = 100;
U_CDECL_BEGIN
static UBool U_CALLCONV unifiedcache_cleanup() {
gCacheInitOnce.reset();
- if (gCache) {
- delete gCache;
- gCache = NULL;
- }
+ delete gCache;
+ gCache = nullptr;
+ gCacheMutex->~mutex();
+ gCacheMutex = nullptr;
+ gInProgressValueAddedCond->~condition_variable();
+ gInProgressValueAddedCond = nullptr;
return TRUE;
}
U_CDECL_END
@@ -77,6 +72,8 @@ static void U_CALLCONV cacheInit(UErrorCode &status) {
ucln_common_registerCleanup(
UCLN_COMMON_UNIFIED_CACHE, unifiedcache_cleanup);
+ gCacheMutex = STATIC_NEW(std::mutex);
+ gInProgressValueAddedCond = STATIC_NEW(std::condition_variable);
gCache = new UnifiedCache(status);
if (gCache == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
@@ -138,28 +135,28 @@ void UnifiedCache::setEvictionPolicy(
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
- Mutex lock(gCacheMutex());
+ std::lock_guard<std::mutex> lock(*gCacheMutex);
fMaxUnused = count;
fMaxPercentageOfInUse = percentageOfInUseItems;
}
int32_t UnifiedCache::unusedCount() const {
- Mutex lock(gCacheMutex());
+ std::lock_guard<std::mutex> lock(*gCacheMutex);
return uhash_count(fHashtable) - fNumValuesInUse;
}
int64_t UnifiedCache::autoEvictedCount() const {
- Mutex lock(gCacheMutex());
+ std::lock_guard<std::mutex> lock(*gCacheMutex);
return fAutoEvictedCount;
}
int32_t UnifiedCache::keyCount() const {
- Mutex lock(gCacheMutex());
+ std::lock_guard<std::mutex> lock(*gCacheMutex);
return uhash_count(fHashtable);
}
void UnifiedCache::flush() const {
- Mutex lock(gCacheMutex());
+ std::lock_guard<std::mutex> lock(*gCacheMutex);
// Use a loop in case cache items that are flushed held hard references to
// other cache items making those additional cache items eligible for
@@ -168,7 +165,7 @@ void UnifiedCache::flush() const {
}
void UnifiedCache::handleUnreferencedObject() const {
- Mutex lock(gCacheMutex());
+ std::lock_guard<std::mutex> lock(*gCacheMutex);
--fNumValuesInUse;
_runEvictionSlice();
}
@@ -187,7 +184,7 @@ void UnifiedCache::dump() {
}
void UnifiedCache::dumpContents() const {
- Mutex lock(gCacheMutex());
+ std::lock_guard<std::mutex> lock(*gCacheMutex);
_dumpContents();
}
@@ -227,7 +224,7 @@ UnifiedCache::~UnifiedCache() {
// Now all that should be left in the cache are entries that refer to
// each other and entries with hard references from outside the cache.
// Nothing we can do about these so proceed to wipe out the cache.
- Mutex lock(gCacheMutex());
+ std::lock_guard<std::mutex> lock(*gCacheMutex);
_flush(TRUE);
}
uhash_close(fHashtable);
@@ -328,7 +325,7 @@ void UnifiedCache::_putIfAbsentAndGet(
const CacheKeyBase &key,
const SharedObject *&value,
UErrorCode &status) const {
- Mutex lock(gCacheMutex());
+ std::lock_guard<std::mutex> lock(*gCacheMutex);
const UHashElement *element = uhash_find(fHashtable, &key);
if (element != NULL && !_inProgress(element)) {
_fetch(element, value, status);
@@ -353,15 +350,15 @@ UBool UnifiedCache::_poll(
UErrorCode &status) const {
U_ASSERT(value == NULL);
U_ASSERT(status == U_ZERO_ERROR);
- Mutex lock(gCacheMutex());
+ std::unique_lock<std::mutex> lock(*gCacheMutex);
const UHashElement *element = uhash_find(fHashtable, &key);
// If the hash table contains an inProgress placeholder entry for this key,
// this means that another thread is currently constructing the value object.
// Loop, waiting for that construction to complete.
while (element != NULL && _inProgress(element)) {
- umtx_condWait(gInProgressValueAddedCond(), gCacheMutex());
- element = uhash_find(fHashtable, &key);
+ gInProgressValueAddedCond->wait(lock);
+ element = uhash_find(fHashtable, &key);
}
// If the hash table contains an entry for the key,
@@ -433,7 +430,7 @@ void UnifiedCache::_put(
// Tell waiting threads that we replace in-progress status with
// an error.
- umtx_condBroadcast(gInProgressValueAddedCond());
+ gInProgressValueAddedCond->notify_all();
}
void UnifiedCache::_fetch(