10 #include "AgoraRefPtr.h"
11 #include "AgoraAtomicOps.h"
13 #ifndef OPTIONAL_REFCOUNTRELEASESTATUS_SPECIFIER
14 #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
15 #define OPTIONAL_REFCOUNTRELEASESTATUS_SPECIFIER agora::RefCountReleaseStatus::
17 #define OPTIONAL_REFCOUNTRELEASESTATUS_SPECIFIER
24 explicit RefCounter(
int ref_count) : ref_count_(ref_count) {}
26 void IncRef() { AtomicOps::Increment(&ref_count_); }
32 agora::RefCountReleaseStatus
DecRef() {
33 return (AtomicOps::Decrement(&ref_count_) == 0
34 ? OPTIONAL_REFCOUNTRELEASESTATUS_SPECIFIER kDroppedLastRef
35 : OPTIONAL_REFCOUNTRELEASESTATUS_SPECIFIER kOtherRefsRemained);
46 bool HasOneRef()
const {
return (AtomicOps::AcquireLoad(&ref_count_) == 1); }
52 volatile int ref_count_;
68 #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
69 explicit RefCountedObject(P0&& p0) : T(std::forward<P0>(p0)), ref_count_(0) {}
74 #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
75 template <
class P0,
class P1,
class... Args>
77 : T(std::forward<P0>(p0),
79 std::forward<Args>(args)...),
83 virtual void AddRef()
const { ref_count_.IncRef(); }
85 virtual agora::RefCountReleaseStatus Release()
const {
86 const agora::RefCountReleaseStatus status = ref_count_.
DecRef();
87 if (status == OPTIONAL_REFCOUNTRELEASESTATUS_SPECIFIER kDroppedLastRef) {
107 RefCountedObject(
const RefCountedObject&);
108 RefCountedObject& operator=(
const RefCountedObject&);
114 #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
115 template <
typename T,
typename... types>
116 inline agora_refptr<T> make_refptr(types&&... args) {
117 return agora_refptr<T>(
new RefCountedObject<T>(std::forward<types>(args)...));
120 template <
typename T>
121 inline agora_refptr<T> make_refptr() {
122 return agora_refptr<T>(
new RefCountedObject<T>());
124 template <
typename T,
typename P0>
125 inline agora_refptr<T> make_refptr(
const P0& p0) {
126 return agora_refptr<T>(
new RefCountedObject<T>(p0));