10 #include "AgoraRefPtr.h"
11 #include "AgoraAtomicOps.h"
17 explicit RefCounter(
int ref_count) : ref_count_(ref_count) {}
19 void IncRef() { AtomicOps::Increment(&ref_count_); }
25 agora::RefCountReleaseStatus
DecRef() {
26 return (AtomicOps::Decrement(&ref_count_) == 0
27 ? agora::RefCountReleaseStatus::kDroppedLastRef
28 : agora::RefCountReleaseStatus::kOtherRefsRemained);
39 bool HasOneRef()
const {
return (AtomicOps::AcquireLoad(&ref_count_) == 1); }
45 volatile int ref_count_;
63 template <
class P0,
class P1,
class... Args>
65 : T(std::forward<P0>(p0),
67 std::forward<Args>(args)...) {}
69 virtual void AddRef()
const { ref_count_.IncRef(); }
71 virtual agora::RefCountReleaseStatus Release()
const {
72 const auto status = ref_count_.
DecRef();
73 if (status == agora::RefCountReleaseStatus::kDroppedLastRef) {
93 RefCountedObject(
const RefCountedObject&);
94 RefCountedObject& operator=(
const RefCountedObject&);
100 template <
typename T,
typename... types>
101 inline agora_refptr<T> make_refptr(types&&... args) {
102 return agora_refptr<T>(
new RefCountedObject<T>(std::forward<types>(args)...));