summaryrefslogtreecommitdiff
path: root/deps/icu-small/source/common/sharedobject.h
diff options
context:
space:
mode:
authorSteven R. Loomis <srloomis@us.ibm.com>2018-03-26 15:29:02 -0700
committerSteven R. Loomis <srloomis@us.ibm.com>2018-04-02 18:18:28 -0700
commit64211405dab824a570e52d000891c49415cc42b8 (patch)
tree4c196d0e2c19e083db1e124139dd4ba6272fd049 /deps/icu-small/source/common/sharedobject.h
parent88773af540a36b23a47af0d6c4ce03b8cc3ef9aa (diff)
downloadandroid-node-v8-64211405dab824a570e52d000891c49415cc42b8.tar.gz
android-node-v8-64211405dab824a570e52d000891c49415cc42b8.tar.bz2
android-node-v8-64211405dab824a570e52d000891c49415cc42b8.zip
deps: ICU 61.1 bump
- Update to released ICU 61.1, including: - CLDR 33 (many new languages and data improvements) - Many small API additions, improvements, and bug fixes - note: 'icu::' namespace is no longer used by default (Necessated https://github.com/nodejs/node/pull/18667 ) PR-URL: https://github.com/nodejs/node/pull/19621 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'deps/icu-small/source/common/sharedobject.h')
-rw-r--r--deps/icu-small/source/common/sharedobject.h116
1 files changed, 32 insertions, 84 deletions
diff --git a/deps/icu-small/source/common/sharedobject.h b/deps/icu-small/source/common/sharedobject.h
index 783b55948a..54655d0d71 100644
--- a/deps/icu-small/source/common/sharedobject.h
+++ b/deps/icu-small/source/common/sharedobject.h
@@ -17,6 +17,8 @@
U_NAMESPACE_BEGIN
+class SharedObject;
+
/**
* Base class for unified cache exposing enough methods to SharedObject
* instances to allow their addRef() and removeRef() methods to
@@ -28,22 +30,12 @@ public:
UnifiedCacheBase() { }
/**
- * Called by addRefWhileHoldingCacheLock() when the hard reference count
- * of its instance goes from 0 to 1.
+ * Notify the cache implementation that an object was seen transitioning to
+ * zero hard references. The cache may use this to keep track the number of
+ * unreferenced SharedObjects, and to trigger evictions.
*/
- virtual void incrementItemsInUse() const = 0;
+ virtual void handleUnreferencedObject() const = 0;
- /**
- * Called by removeRef() when the hard reference count of its instance
- * drops from 1 to 0.
- */
- virtual void decrementItemsInUseWithLockingAndEviction() const = 0;
-
- /**
- * Called by removeRefWhileHoldingCacheLock() when the hard reference
- * count of its instance drops from 1 to 0.
- */
- virtual void decrementItemsInUse() const = 0;
virtual ~UnifiedCacheBase();
private:
UnifiedCacheBase(const UnifiedCacheBase &);
@@ -63,7 +55,6 @@ class U_COMMON_API SharedObject : public UObject {
public:
/** Initializes totalRefCount, softRefCount to 0. */
SharedObject() :
- totalRefCount(0),
softRefCount(0),
hardRefCount(0),
cachePtr(NULL) {}
@@ -71,7 +62,6 @@ public:
/** Initializes totalRefCount, softRefCount to 0. */
SharedObject(const SharedObject &other) :
UObject(other),
- totalRefCount(0),
softRefCount(0),
hardRefCount(0),
cachePtr(NULL) {}
@@ -79,93 +69,45 @@ public:
virtual ~SharedObject();
/**
- * Increments the number of references to this object. Thread-safe.
+ * Increments the number of hard references to this object. Thread-safe.
+ * Not for use from within the Unified Cache implementation.
*/
- void addRef() const { addRef(FALSE); }
+ void addRef() const;
/**
- * Increments the number of references to this object.
- * Must be called only from within the internals of UnifiedCache and
- * only while the cache global mutex is held.
- */
- void addRefWhileHoldingCacheLock() const { addRef(TRUE); }
-
- /**
- * Increments the number of soft references to this object.
- * Must be called only from within the internals of UnifiedCache and
- * only while the cache global mutex is held.
- */
- void addSoftRef() const;
-
- /**
- * Decrements the number of references to this object. Thread-safe.
- */
- void removeRef() const { removeRef(FALSE); }
-
- /**
- * Decrements the number of references to this object.
- * Must be called only from within the internals of UnifiedCache and
- * only while the cache global mutex is held.
- */
- void removeRefWhileHoldingCacheLock() const { removeRef(TRUE); }
-
- /**
- * Decrements the number of soft references to this object.
- * Must be called only from within the internals of UnifiedCache and
- * only while the cache global mutex is held.
+ * Decrements the number of hard references to this object, and
+ * arrange for possible cache-eviction and/or deletion if ref
+ * count goes to zero. Thread-safe.
+ *
+ * Not for use from within the UnifiedCache implementation.
*/
- void removeSoftRef() const;
+ void removeRef() const;
/**
- * Returns the reference counter including soft references.
+ * Returns the number of hard references for this object.
* Uses a memory barrier.
*/
int32_t getRefCount() const;
/**
- * Returns the count of soft references only.
- * Must be called only from within the internals of UnifiedCache and
- * only while the cache global mutex is held.
- */
- int32_t getSoftRefCount() const { return softRefCount; }
-
- /**
- * Returns the count of hard references only. Uses a memory barrier.
- * Used for testing the cache. Regular clients won't need this.
- */
- int32_t getHardRefCount() const;
-
- /**
* If noHardReferences() == TRUE then this object has no hard references.
* Must be called only from within the internals of UnifiedCache.
*/
- inline UBool noHardReferences() const { return getHardRefCount() == 0; }
+ inline UBool noHardReferences() const { return getRefCount() == 0; }
/**
* If hasHardReferences() == TRUE then this object has hard references.
* Must be called only from within the internals of UnifiedCache.
*/
- inline UBool hasHardReferences() const { return getHardRefCount() != 0; }
-
- /**
- * If noSoftReferences() == TRUE then this object has no soft references.
- * Must be called only from within the internals of UnifiedCache and
- * only while the cache global mutex is held.
- */
- UBool noSoftReferences() const { return (softRefCount == 0); }
+ inline UBool hasHardReferences() const { return getRefCount() != 0; }
/**
- * Deletes this object if it has no references or soft references.
+ * Deletes this object if it has no references.
+ * Available for non-cached SharedObjects only. Ownership of cached objects
+ * is with the UnifiedCache, which is soley responsible for eviction and deletion.
*/
void deleteIfZeroRefCount() const;
- /**
- * @internal For UnifedCache use only to register this object with itself.
- * Must be called before this object is exposed to multiple threads.
- */
- void registerWithCache(const UnifiedCacheBase *ptr) const {
- cachePtr = ptr;
- }
/**
* Returns a writable version of ptr.
@@ -219,15 +161,21 @@ public:
}
private:
- mutable u_atomic_int32_t totalRefCount;
-
- // Any thread modifying softRefCount must hold the global cache mutex
+ /**
+ * The number of references from the UnifiedCache, which is
+ * the number of times that the sharedObject is stored as a hash table value.
+ * For use by UnifiedCache implementation code only.
+ * All access is synchronized by UnifiedCache's gCacheMutex
+ */
mutable int32_t softRefCount;
+ friend class UnifiedCache;
+ /**
+ * Reference count, excluding references from within the UnifiedCache implementation.
+ */
mutable u_atomic_int32_t hardRefCount;
+
mutable const UnifiedCacheBase *cachePtr;
- void addRef(UBool withCacheLock) const;
- void removeRef(UBool withCacheLock) const;
};