From eaad6ba6e0a175cfa9f930bf459cdd69d41756d3 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 23 Feb 2026 22:33:09 -0500 Subject: [PATCH] Replace root class with rcp_root() macro --- include/rcp.h | 37 +++++++++++++++---------------------- test/tests.cpp | 4 +++- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/include/rcp.h b/include/rcp.h index c7482cc..0885d57 100644 --- a/include/rcp.h +++ b/include/rcp.h @@ -96,28 +96,21 @@ public: } }; -class root -{ -private: - mutable std::atomic 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 ref_count{0} #define rcp_managed(classname) \ rcp get_rcp() \ diff --git a/test/tests.cpp b/test/tests.cpp index 606b375..59ad9fb 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -6,8 +6,10 @@ static int mybase_destruct; static int myderived_construct; static int myderived_destruct; -class MyBase : public root +class MyBase { + rcp_root(); + protected: MyBase(int x, int y) {