xo-reader2 stack: + ARuntimeContext.collector()
access Collector API (if present) from runtime context
This commit is contained in:
parent
9a6b01d328
commit
f483d3db41
9 changed files with 50 additions and 1 deletions
|
|
@ -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<ACollector>",
|
||||
args: [],
|
||||
const: true,
|
||||
noexcept: true,
|
||||
attributes: [],
|
||||
},
|
||||
{
|
||||
name: "stringtable",
|
||||
doc: [ "stringtable for unique symbols" ],
|
||||
|
|
|
|||
|
|
@ -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<AAllocator> mm, StringTable * st)
|
||||
: allocator_{mm}, stringtable_{st} {}
|
||||
: allocator_{mm}, stringtable_{st} {}
|
||||
|
||||
obj<AAllocator> allocator() const noexcept { return allocator_; }
|
||||
obj<ACollector> collector() const noexcept;
|
||||
StringTable * stringtable() const noexcept { return stringtable_; }
|
||||
void visit_pools(const MemorySizeVisitor & visitor) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -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<AAllocator> allocator(Copaque data) const noexcept = 0;
|
||||
/** collector facet for allocator. If non-null, same data pointer as allocator **/
|
||||
virtual obj<ACollector> 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 **/
|
||||
|
|
|
|||
|
|
@ -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<AAllocator> allocator(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] obj<ACollector> collector(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] StringTable * stringtable(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] void visit_pools(Copaque, MemorySizeVisitor) const override { _fatal(); }
|
||||
|
||||
|
|
|
|||
|
|
@ -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<AAllocator> allocator(const DSimpleRcx & self) noexcept;
|
||||
/** collector facet for allocator. If non-null, same data pointer as allocator **/
|
||||
static obj<ACollector> collector(const DSimpleRcx & self) noexcept;
|
||||
/** stringtable for unique symbols **/
|
||||
static StringTable * stringtable(const DSimpleRcx & self) noexcept;
|
||||
/** invoke visitor for each distinct memory pool **/
|
||||
|
|
|
|||
|
|
@ -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<AAllocator> allocator(Copaque data) const noexcept override {
|
||||
return I::allocator(_dcast(data));
|
||||
}
|
||||
obj<ACollector> collector(Copaque data) const noexcept override {
|
||||
return I::collector(_dcast(data));
|
||||
}
|
||||
StringTable * stringtable(Copaque data) const noexcept override {
|
||||
return I::stringtable(_dcast(data));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<AAllocator> allocator() const noexcept {
|
||||
return O::iface()->allocator(O::data());
|
||||
}
|
||||
obj<ACollector> collector() const noexcept {
|
||||
return O::iface()->collector(O::data());
|
||||
}
|
||||
StringTable * stringtable() const noexcept {
|
||||
return O::iface()->stringtable(O::data());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,20 @@
|
|||
**/
|
||||
|
||||
#include "DSimpleRcx.hpp"
|
||||
#include <xo/alloc2/Collector.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::ACollector;
|
||||
|
||||
namespace scm {
|
||||
|
||||
obj<ACollector>
|
||||
DSimpleRcx::collector() const noexcept
|
||||
{
|
||||
return allocator_.try_to_facet<ACollector>();
|
||||
}
|
||||
|
||||
void
|
||||
DSimpleRcx::visit_pools(const MemorySizeVisitor & visitor) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,6 +21,12 @@ namespace xo {
|
|||
return self.allocator();
|
||||
}
|
||||
|
||||
auto
|
||||
IRuntimeContext_DSimpleRcx::collector(const DSimpleRcx & self) noexcept -> obj<ACollector>
|
||||
{
|
||||
return self.collector();
|
||||
}
|
||||
|
||||
auto
|
||||
IRuntimeContext_DSimpleRcx::stringtable(const DSimpleRcx & self) noexcept -> StringTable *
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue