Replace root class with rcp_root() macro
This commit is contained in:
1 parent
a70a0218dc
commit
eaad6ba6e0
2 files changed
+18
-23
No files matched your search
+15
-22
@@ -96,28 +96,21 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class root
|
||||
{
|
||||
private:
|
||||
mutable std::atomic<int> ref_count{0};
|
||||
|
||||
protected:
|
||||
virtual ~root() = default;
|
||||
|
||||
public:
|
||||
void rcp_inc() const
|
||||
{
|
||||
ref_count.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
void rcp_dec() const
|
||||
{
|
||||
if (ref_count.fetch_sub(1, std::memory_order_acq_rel) == 1)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
};
|
||||
#define rcp_root() \
|
||||
public: \
|
||||
void rcp_inc() const \
|
||||
{ \
|
||||
ref_count.fetch_add(1, std::memory_order_relaxed); \
|
||||
} \
|
||||
void rcp_dec() const \
|
||||
{ \
|
||||
if (ref_count.fetch_sub(1, std::memory_order_acq_rel) == 1) \
|
||||
{ \
|
||||
delete this; \
|
||||
} \
|
||||
} \
|
||||
private: \
|
||||
mutable std::atomic<int> ref_count{0}
|
||||
|
||||
#define rcp_managed(classname) \
|
||||
rcp<classname> get_rcp() \
|
||||
|
||||
Reference in new issue
Block a user