refactor: + narrower interface for gc pointer forwarding
add AGCObjectVisitor, instead of requiring ACollector.
This commit is contained in:
parent
327807331d
commit
72cbffba46
8 changed files with 25 additions and 15 deletions
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include <xo/alloc2/Collector.hpp>
|
||||
#include <xo/alloc2/GCObjectVisitor.hpp>
|
||||
#include <xo/facet/obj.hpp>
|
||||
#include <xo/indentlog/print/ppindentinfo.hpp>
|
||||
#include <string_view>
|
||||
|
|
@ -47,6 +48,8 @@ namespace xo {
|
|||
using AAllocator = xo::mm::AAllocator;
|
||||
/** garbage collector **/
|
||||
using ACollector = xo::mm::ACollector;
|
||||
/** object visitor (garbage collector proxy) **/
|
||||
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
|
||||
/** ppindentinfo for APrintable **/
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
///@}
|
||||
|
|
@ -247,10 +250,10 @@ namespace xo {
|
|||
/** clone string, using memory from allocator @p mm **/
|
||||
DString * shallow_move(obj<ACollector> gc) noexcept;
|
||||
|
||||
size_type forward_children(obj<ACollector> gc) noexcept;
|
||||
/** fixup child pointers (trivial for DString, no children)
|
||||
* note: cref so we can use forward decl
|
||||
**/
|
||||
void visit_gco_children(obj<AGCObjectVisitor> gc) noexcept;
|
||||
|
||||
///@}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ namespace xo {
|
|||
public:
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using ACollector = xo::mm::ACollector;
|
||||
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
|
||||
using size_type = DString::size_type;
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
|
||||
|
|
@ -92,7 +93,7 @@ namespace xo {
|
|||
DUniqueString * shallow_move(obj<ACollector> gc) noexcept;
|
||||
|
||||
/** fixup child pointers (trivial for DUniqueString, no gc-owned children **/
|
||||
void forward_children(obj<ACollector> gc) noexcept;
|
||||
void visit_gco_children(obj<AGCObjectVisitor> gc) noexcept;
|
||||
|
||||
///@}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ namespace xo {
|
|||
using size_type = xo::mm::AGCObject::size_type;
|
||||
using AAllocator = xo::mm::AGCObject::AAllocator;
|
||||
using ACollector = xo::mm::AGCObject::ACollector;
|
||||
using AGCObjectVisitor = xo::mm::AGCObject::AGCObjectVisitor;
|
||||
using Copaque = xo::mm::AGCObject::Copaque;
|
||||
using Opaque = xo::mm::AGCObject::Opaque;
|
||||
///@}
|
||||
|
|
@ -54,8 +55,10 @@ namespace xo {
|
|||
// non-const methods
|
||||
/** move instance using allocator **/
|
||||
static Opaque shallow_move(DString & self, obj<ACollector> gc) noexcept;
|
||||
/** during GC: forward immdiate children **/
|
||||
static void forward_children(DString & self, obj<ACollector> gc) noexcept;
|
||||
/** Invoke fn.visit_child(iface,data) for each child GCObject pointer.
|
||||
Context: provides address of data pointer so it can be updated in place
|
||||
when @p fn invokes garbage collector reentry point **/
|
||||
static void visit_gco_children(DString & self, obj<AGCObjectVisitor> fn) noexcept;
|
||||
///@}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ namespace xo {
|
|||
using size_type = xo::mm::AGCObject::size_type;
|
||||
using AAllocator = xo::mm::AGCObject::AAllocator;
|
||||
using ACollector = xo::mm::AGCObject::ACollector;
|
||||
using AGCObjectVisitor = xo::mm::AGCObject::AGCObjectVisitor;
|
||||
using Copaque = xo::mm::AGCObject::Copaque;
|
||||
using Opaque = xo::mm::AGCObject::Opaque;
|
||||
///@}
|
||||
|
|
@ -54,8 +55,10 @@ namespace xo {
|
|||
// non-const methods
|
||||
/** move instance using allocator **/
|
||||
static Opaque shallow_move(DUniqueString & self, obj<ACollector> gc) noexcept;
|
||||
/** during GC: forward immdiate children **/
|
||||
static void forward_children(DUniqueString & self, obj<ACollector> gc) noexcept;
|
||||
/** Invoke fn.visit_child(iface,data) for each child GCObject pointer.
|
||||
Context: provides address of data pointer so it can be updated in place
|
||||
when @p fn invokes garbage collector reentry point **/
|
||||
static void visit_gco_children(DUniqueString & self, obj<AGCObjectVisitor> fn) noexcept;
|
||||
///@}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -172,10 +172,10 @@ namespace xo {
|
|||
return copy;
|
||||
}
|
||||
|
||||
auto
|
||||
DString::forward_children(obj<ACollector>) noexcept -> size_type
|
||||
void
|
||||
DString::visit_gco_children(obj<AGCObjectVisitor>) noexcept
|
||||
{
|
||||
return shallow_size();
|
||||
// no-op. no children!
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -109,9 +109,9 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
DUniqueString::forward_children(obj<ACollector>) noexcept
|
||||
DUniqueString::visit_gco_children(obj<AGCObjectVisitor>) noexcept
|
||||
{
|
||||
// no-op
|
||||
// no-op -- childless!
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ namespace xo {
|
|||
return self.shallow_move(gc);
|
||||
}
|
||||
auto
|
||||
IGCObject_DString::forward_children(DString & self, obj<ACollector> gc) noexcept -> void
|
||||
IGCObject_DString::visit_gco_children(DString & self, obj<AGCObjectVisitor> fn) noexcept -> void
|
||||
{
|
||||
self.forward_children(gc);
|
||||
self.visit_gco_children(fn);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ namespace xo {
|
|||
return self.shallow_move(gc);
|
||||
}
|
||||
auto
|
||||
IGCObject_DUniqueString::forward_children(DUniqueString & self, obj<ACollector> gc) noexcept -> void
|
||||
IGCObject_DUniqueString::visit_gco_children(DUniqueString & self, obj<AGCObjectVisitor> fn) noexcept -> void
|
||||
{
|
||||
self.forward_children(gc);
|
||||
self.visit_gco_children(fn);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue