]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/sharedobject.cpp
ICU-531.30.tar.gz
[apple/icu.git] / icuSources / common / sharedobject.cpp
diff --git a/icuSources/common/sharedobject.cpp b/icuSources/common/sharedobject.cpp
new file mode 100644 (file)
index 0000000..bad7980
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+******************************************************************************
+* Copyright (C) 2014, International Business Machines
+* Corporation and others.  All Rights Reserved.
+******************************************************************************
+* sharedobject.cpp
+*/
+#include "sharedobject.h"
+
+U_NAMESPACE_BEGIN
+SharedObject::~SharedObject() {}
+
+void
+SharedObject::addRef() const {
+    umtx_atomic_inc(&refCount);
+}
+
+void
+SharedObject::removeRef() const {
+    if(umtx_atomic_dec(&refCount) == 0) {
+        delete this;
+    }
+}
+
+int32_t
+SharedObject::getRefCount() const {
+    return umtx_loadAcquire(refCount);
+}
+
+void
+SharedObject::deleteIfZeroRefCount() const {
+    if(getRefCount() == 0) {
+        delete this;
+    }
+}
+
+U_NAMESPACE_END