X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/efa1e6592fb03ce23b15276b2b91d885a3ee7da5..57a6839dcb3bba09e8228b822b290604668416fe:/icuSources/common/sharedobject.cpp diff --git a/icuSources/common/sharedobject.cpp b/icuSources/common/sharedobject.cpp new file mode 100644 index 00000000..bad79801 --- /dev/null +++ b/icuSources/common/sharedobject.cpp @@ -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