summaryrefslogtreecommitdiffstats
path: root/intl/icu/source/common/sharedobject.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /intl/icu/source/common/sharedobject.cpp
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'intl/icu/source/common/sharedobject.cpp')
-rw-r--r--intl/icu/source/common/sharedobject.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/intl/icu/source/common/sharedobject.cpp b/intl/icu/source/common/sharedobject.cpp
new file mode 100644
index 0000000000..6eeca8605f
--- /dev/null
+++ b/intl/icu/source/common/sharedobject.cpp
@@ -0,0 +1,62 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+* sharedobject.cpp
+*/
+#include "sharedobject.h"
+#include "mutex.h"
+#include "uassert.h"
+#include "umutex.h"
+#include "unifiedcache.h"
+
+U_NAMESPACE_BEGIN
+
+SharedObject::~SharedObject() {}
+
+UnifiedCacheBase::~UnifiedCacheBase() {}
+
+void
+SharedObject::addRef() const {
+ umtx_atomic_inc(&hardRefCount);
+}
+
+// removeRef Decrement the reference count and delete if it is zero.
+// Note that SharedObjects with a non-null cachePtr are owned by the
+// unified cache, and the cache will be responsible for the actual deletion.
+// The deletion could be as soon as immediately following the
+// update to the reference count, if another thread is running
+// a cache eviction cycle concurrently.
+// NO ACCESS TO *this PERMITTED AFTER REFERENCE COUNT == 0 for cached objects.
+// THE OBJECT MAY ALREADY BE GONE.
+void
+SharedObject::removeRef() const {
+ const UnifiedCacheBase *cache = this->cachePtr;
+ int32_t updatedRefCount = umtx_atomic_dec(&hardRefCount);
+ U_ASSERT(updatedRefCount >= 0);
+ if (updatedRefCount == 0) {
+ if (cache) {
+ cache->handleUnreferencedObject();
+ } else {
+ delete this;
+ }
+ }
+}
+
+
+int32_t
+SharedObject::getRefCount() const {
+ return umtx_loadAcquire(hardRefCount);
+}
+
+void
+SharedObject::deleteIfZeroRefCount() const {
+ if (this->cachePtr == nullptr && getRefCount() == 0) {
+ delete this;
+ }
+}
+
+U_NAMESPACE_END