Remove root_rcp
This commit is contained in:
parent
3fdb7c9bc6
commit
a70a0218dc
@ -33,16 +33,17 @@ class rcp
|
|||||||
private:
|
private:
|
||||||
T * ptr = nullptr;
|
T * ptr = nullptr;
|
||||||
|
|
||||||
void init_ptr(T * p)
|
|
||||||
{
|
|
||||||
ptr = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend T;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
rcp() = default;
|
rcp() = default;
|
||||||
|
|
||||||
|
rcp(T * p) : ptr(p)
|
||||||
|
{
|
||||||
|
if (p)
|
||||||
|
{
|
||||||
|
p->rcp_inc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rcp(const rcp & other) : ptr(other.ptr)
|
rcp(const rcp & other) : ptr(other.ptr)
|
||||||
{
|
{
|
||||||
if (ptr)
|
if (ptr)
|
||||||
@ -101,13 +102,6 @@ private:
|
|||||||
mutable std::atomic<int> ref_count{0};
|
mutable std::atomic<int> ref_count{0};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
mutable rcp<root> root_rcp;
|
|
||||||
|
|
||||||
root()
|
|
||||||
{
|
|
||||||
root_rcp.init_ptr(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~root() = default;
|
virtual ~root() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -120,7 +114,6 @@ public:
|
|||||||
{
|
{
|
||||||
if (ref_count.fetch_sub(1, std::memory_order_acq_rel) == 1)
|
if (ref_count.fetch_sub(1, std::memory_order_acq_rel) == 1)
|
||||||
{
|
{
|
||||||
root_rcp.init_ptr(nullptr);
|
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,7 +122,7 @@ public:
|
|||||||
#define rcp_managed(classname) \
|
#define rcp_managed(classname) \
|
||||||
rcp<classname> get_rcp() \
|
rcp<classname> get_rcp() \
|
||||||
{ \
|
{ \
|
||||||
return rcp<classname>(root_rcp); \
|
return rcp<classname>(this); \
|
||||||
} \
|
} \
|
||||||
template <typename... Args> \
|
template <typename... Args> \
|
||||||
static rcp<classname> create(Args&&... args) \
|
static rcp<classname> create(Args&&... args) \
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user