1 /* 2 ****************************************************************************** 3 * Copyright (C) 2014, International Business Machines 4 * Corporation and others. All Rights Reserved. 5 ****************************************************************************** 6 * sharedobject.cpp 7 */ 8 #include "sharedobject.h" 9 10 U_NAMESPACE_BEGIN 11 SharedObject::~SharedObject() {} 12 13 void 14 SharedObject::addRef() const { 15 umtx_atomic_inc(&refCount); 16 } 17 18 void 19 SharedObject::removeRef() const { 20 if(umtx_atomic_dec(&refCount) == 0) { 21 delete this; 22 } 23 } 24 25 int32_t 26 SharedObject::getRefCount() const { 27 return umtx_loadAcquire(refCount); 28 } 29 30 void 31 SharedObject::deleteIfZeroRefCount() const { 32 if(getRefCount() == 0) { 33 delete this; 34 } 35 } 36 37 U_NAMESPACE_END 38