5#ifndef RUNTIME_BIN_REFERENCE_COUNTING_H_
6#define RUNTIME_BIN_REFERENCE_COUNTING_H_
16template <
class Target>
17class RefCntReleaseScope;
35template <
class Derived>
40 instances_.fetch_add(1u, std::memory_order_relaxed);
47 instances_.fetch_sub(1u, std::memory_order_relaxed);
52 intptr_t old = ref_count_.fetch_add(1u, std::memory_order_relaxed);
57 intptr_t old = ref_count_.fetch_sub(1u, std::memory_order_acq_rel);
60 delete static_cast<Derived*
>(
this);
65 static intptr_t instances() {
66 return instances_.load(std::memory_order_relaxed);
72 static std::atomic<intptr_t> instances_;
75 std::atomic<intptr_t> ref_count_;
78 intptr_t ref_count()
const {
79 return ref_count_.load(std::memory_order_relaxed);
86template <
class Derived>
87std::atomic<intptr_t> ReferenceCounted<Derived>::instances_ = {0};
99template <
class Target>
103 ASSERT(target_ !=
nullptr);
104 ASSERT(target_->ref_count() > 0);
111 DISALLOW_ALLOCATION();
141template <
class Target>
147 if (target_ !=
nullptr) {
153 if (target_ !=
nullptr) {
159 if (target_ !=
nullptr) {
163 if (target_ !=
nullptr) {
173 DISALLOW_ALLOCATION();
RefCntReleaseScope(ReferenceCounted< Target > *t)
virtual ~ReferenceCounted()
RetainedPointer(ReferenceCounted< Target > *t)
void set(ReferenceCounted< Target > *t)