Drop rcp_internal namespace for now to get working
This commit is contained in:
1 parent
6fec208922
commit
f5d52dfe98
2 files changed
+50
-56
No files matched your search
+48
-55
@@ -24,58 +24,6 @@
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace rcp_internal
|
||||
{
|
||||
class root
|
||||
{
|
||||
private:
|
||||
mutable std::atomic<int> ref_count{0};
|
||||
|
||||
rcp<root> root_rcp;
|
||||
|
||||
protected:
|
||||
root()
|
||||
{
|
||||
root_rcp = rcp<root>(this);
|
||||
}
|
||||
|
||||
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) == 0)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
rcp<root> & get_root_rcp()
|
||||
{
|
||||
return root_rcp;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class managed
|
||||
{
|
||||
public:
|
||||
static_assert(std::is_base_of<root, T>::value,
|
||||
"T must inherit from rcp::root to use rcp::managed<T>");
|
||||
|
||||
rcp<T> get_rcp()
|
||||
{
|
||||
root * r = (root *)this;
|
||||
return rcp<T>(r->get_root_ref());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reference-counting pointer.
|
||||
*/
|
||||
@@ -138,8 +86,53 @@ public:
|
||||
{
|
||||
return !ptr;
|
||||
}
|
||||
};
|
||||
|
||||
using root = rcp_internal::root;
|
||||
class root
|
||||
{
|
||||
private:
|
||||
mutable std::atomic<int> ref_count{0};
|
||||
|
||||
using managed = rcp_internal::managed;
|
||||
}
|
||||
rcp<root> root_rcp;
|
||||
|
||||
protected:
|
||||
root()
|
||||
{
|
||||
root_rcp = rcp<root>(this);
|
||||
}
|
||||
|
||||
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) == 0)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
rcp<root> & get_root_rcp()
|
||||
{
|
||||
return root_rcp;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class managed
|
||||
{
|
||||
public:
|
||||
static_assert(std::is_base_of<root, T>::value,
|
||||
"T must inherit from rcp::root to use rcp::managed<T>");
|
||||
|
||||
rcp<T> get_rcp()
|
||||
{
|
||||
root * r = (root *)this;
|
||||
return rcp<T>(r->get_root_rcp());
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user