79 std::printf(
"object ref count is not 0, can not destruct");
90 return aObject_IncWeakRef(
this);
97 return aObject_DecWeakRef(
this);
104 return aObject_IncRef(
this);
111 return aObject_DecRef(
this);
123 friend uint32_t aObject_IncRef(
Referenced* obj)
125 return ++(obj->refcnt_);
128 friend uint32_t aObject_DecRef(Referenced* obj)
130 if (obj->refcnt_ == 1) {
134 return --(obj->refcnt_);
137 friend uint32_t aObject_IncWeakRef(Referenced* obj)
139 return ++(obj->weakrefcnt_);
142 friend uint32_t aObject_DecWeakRef(Referenced* obj)
144 if (obj->weakrefcnt_ == 1) {
145 operator delete(obj);
149 return --(obj->weakrefcnt_);
153 friend bool aObject_IsDestructed(
const Referenced *obj)
155 return obj->refcnt_ ==
static_cast<uint32_t
>(-1);
160 this->refcnt_ =
static_cast<uint32_t
>(-1);
171 std::atomic<uint32_t> refcnt_{0};
172 std::atomic<uint32_t> weakrefcnt_{1};