diff --git a/idl/RuntimeContext.json5 b/idl/RuntimeContext.json5 index fe1254b..481d0cb 100644 --- a/idl/RuntimeContext.json5 +++ b/idl/RuntimeContext.json5 @@ -31,6 +31,11 @@ definition: "xo::mm::AAllocator", doc: [ "xo memory allocator" ], }, + { + name: "ACollector", + definition: "xo::mm::ACollector", + doc: [ "xo garbage collector" ], + }, { name: "MemorySizeVisitor", definition: "xo::mm::MemorySizeVisitor", @@ -47,6 +52,15 @@ noexcept: true, attributes: [], }, + { + name: "collector", + doc: [ "collector facet for allocator. If non-null, same data pointer as allocator" ], + return_type: "obj", + args: [], + const: true, + noexcept: true, + attributes: [], + }, { name: "stringtable", doc: [ "stringtable for unique symbols" ], diff --git a/include/xo/procedure2/DSimpleRcx.hpp b/include/xo/procedure2/DSimpleRcx.hpp index 6a7163d..f6bee0b 100644 --- a/include/xo/procedure2/DSimpleRcx.hpp +++ b/include/xo/procedure2/DSimpleRcx.hpp @@ -19,13 +19,15 @@ namespace xo { class DSimpleRcx { public: using AAllocator = xo::mm::AAllocator; + using ACollector = xo::mm::ACollector; using MemorySizeVisitor = xo::mm::MemorySizeVisitor; public: DSimpleRcx(obj mm, StringTable * st) - : allocator_{mm}, stringtable_{st} {} + : allocator_{mm}, stringtable_{st} {} obj allocator() const noexcept { return allocator_; } + obj collector() const noexcept; StringTable * stringtable() const noexcept { return stringtable_; } void visit_pools(const MemorySizeVisitor & visitor) const; diff --git a/include/xo/procedure2/detail/ARuntimeContext.hpp b/include/xo/procedure2/detail/ARuntimeContext.hpp index 716463d..626e2ba 100644 --- a/include/xo/procedure2/detail/ARuntimeContext.hpp +++ b/include/xo/procedure2/detail/ARuntimeContext.hpp @@ -42,6 +42,8 @@ public: using Opaque = void *; /** xo memory allocator **/ using AAllocator = xo::mm::AAllocator; + /** xo garbage collector **/ + using ACollector = xo::mm::ACollector; /** function to visit memory pools **/ using MemorySizeVisitor = xo::mm::MemorySizeVisitor; ///@} @@ -55,6 +57,8 @@ public: virtual void _drop(Opaque d) const noexcept = 0; /** default allocator to use for objects **/ virtual obj allocator(Copaque data) const noexcept = 0; + /** collector facet for allocator. If non-null, same data pointer as allocator **/ + virtual obj collector(Copaque data) const noexcept = 0; /** stringtable for unique symbols **/ virtual StringTable * stringtable(Copaque data) const noexcept = 0; /** invoke visitor for each distinct memory pool **/ diff --git a/include/xo/procedure2/detail/IRuntimeContext_Any.hpp b/include/xo/procedure2/detail/IRuntimeContext_Any.hpp index b72f934..d0789e5 100644 --- a/include/xo/procedure2/detail/IRuntimeContext_Any.hpp +++ b/include/xo/procedure2/detail/IRuntimeContext_Any.hpp @@ -45,6 +45,7 @@ namespace scm { /** integer identifying a type **/ using typeseq = xo::facet::typeseq; using AAllocator = ARuntimeContext::AAllocator; + using ACollector = ARuntimeContext::ACollector; using MemorySizeVisitor = ARuntimeContext::MemorySizeVisitor; ///@} @@ -61,6 +62,7 @@ namespace scm { // const methods [[noreturn]] obj allocator(Copaque) const noexcept override { _fatal(); } + [[noreturn]] obj collector(Copaque) const noexcept override { _fatal(); } [[noreturn]] StringTable * stringtable(Copaque) const noexcept override { _fatal(); } [[noreturn]] void visit_pools(Copaque, MemorySizeVisitor) const override { _fatal(); } diff --git a/include/xo/procedure2/detail/IRuntimeContext_DSimpleRcx.hpp b/include/xo/procedure2/detail/IRuntimeContext_DSimpleRcx.hpp index 82ab521..496b593 100644 --- a/include/xo/procedure2/detail/IRuntimeContext_DSimpleRcx.hpp +++ b/include/xo/procedure2/detail/IRuntimeContext_DSimpleRcx.hpp @@ -40,6 +40,7 @@ namespace xo { /** @defgroup scm-runtimecontext-dsimplercx-type-traits **/ ///@{ using AAllocator = xo::scm::ARuntimeContext::AAllocator; + using ACollector = xo::scm::ARuntimeContext::ACollector; using MemorySizeVisitor = xo::scm::ARuntimeContext::MemorySizeVisitor; using Copaque = xo::scm::ARuntimeContext::Copaque; using Opaque = xo::scm::ARuntimeContext::Opaque; @@ -49,6 +50,8 @@ namespace xo { // const methods /** default allocator to use for objects **/ static obj allocator(const DSimpleRcx & self) noexcept; + /** collector facet for allocator. If non-null, same data pointer as allocator **/ + static obj collector(const DSimpleRcx & self) noexcept; /** stringtable for unique symbols **/ static StringTable * stringtable(const DSimpleRcx & self) noexcept; /** invoke visitor for each distinct memory pool **/ diff --git a/include/xo/procedure2/detail/IRuntimeContext_Xfer.hpp b/include/xo/procedure2/detail/IRuntimeContext_Xfer.hpp index 5dc9de5..2c4e80e 100644 --- a/include/xo/procedure2/detail/IRuntimeContext_Xfer.hpp +++ b/include/xo/procedure2/detail/IRuntimeContext_Xfer.hpp @@ -31,6 +31,7 @@ namespace scm { /** integer identifying a type **/ using typeseq = ARuntimeContext::typeseq; using AAllocator = ARuntimeContext::AAllocator; + using ACollector = ARuntimeContext::ACollector; using MemorySizeVisitor = ARuntimeContext::MemorySizeVisitor; ///@} @@ -50,6 +51,9 @@ namespace scm { obj allocator(Copaque data) const noexcept override { return I::allocator(_dcast(data)); } + obj collector(Copaque data) const noexcept override { + return I::collector(_dcast(data)); + } StringTable * stringtable(Copaque data) const noexcept override { return I::stringtable(_dcast(data)); } diff --git a/include/xo/procedure2/detail/RRuntimeContext.hpp b/include/xo/procedure2/detail/RRuntimeContext.hpp index 6553648..b80cfce 100644 --- a/include/xo/procedure2/detail/RRuntimeContext.hpp +++ b/include/xo/procedure2/detail/RRuntimeContext.hpp @@ -32,6 +32,7 @@ public: using DataPtr = Object::DataPtr; using typeseq = xo::reflect::typeseq; using AAllocator = ARuntimeContext::AAllocator; + using ACollector = ARuntimeContext::ACollector; using MemorySizeVisitor = ARuntimeContext::MemorySizeVisitor; ///@} @@ -57,6 +58,9 @@ public: obj allocator() const noexcept { return O::iface()->allocator(O::data()); } + obj collector() const noexcept { + return O::iface()->collector(O::data()); + } StringTable * stringtable() const noexcept { return O::iface()->stringtable(O::data()); } diff --git a/src/procedure2/DSimpleRcx.cpp b/src/procedure2/DSimpleRcx.cpp index 30ec9c9..471cad7 100644 --- a/src/procedure2/DSimpleRcx.cpp +++ b/src/procedure2/DSimpleRcx.cpp @@ -4,10 +4,20 @@ **/ #include "DSimpleRcx.hpp" +#include +#include namespace xo { + using xo::mm::ACollector; + namespace scm { + obj + DSimpleRcx::collector() const noexcept + { + return allocator_.try_to_facet(); + } + void DSimpleRcx::visit_pools(const MemorySizeVisitor & visitor) const { diff --git a/src/procedure2/facet/IRuntimeContext_DSimpleRcx.cpp b/src/procedure2/facet/IRuntimeContext_DSimpleRcx.cpp index 82dd310..ba56096 100644 --- a/src/procedure2/facet/IRuntimeContext_DSimpleRcx.cpp +++ b/src/procedure2/facet/IRuntimeContext_DSimpleRcx.cpp @@ -21,6 +21,12 @@ namespace xo { return self.allocator(); } + auto + IRuntimeContext_DSimpleRcx::collector(const DSimpleRcx & self) noexcept -> obj + { + return self.collector(); + } + auto IRuntimeContext_DSimpleRcx::stringtable(const DSimpleRcx & self) noexcept -> StringTable * {