xo-facet: typeseq strongly typed
This commit is contained in:
parent
90bb58e186
commit
3af1cf1bda
12 changed files with 38 additions and 24 deletions
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "AllocInfo.hpp"
|
||||
#include "cmpresult.hpp"
|
||||
#include "typeseq.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
|
||||
namespace xo {
|
||||
|
|
@ -22,11 +23,12 @@ namespace xo {
|
|||
**/
|
||||
struct AAllocIterator {
|
||||
using obj_AAllocIterator = xo::facet::obj<AAllocIterator>;
|
||||
using typeseq = xo::facet::typeseq;
|
||||
|
||||
/** @defgroup mm-allociterator-methods AllocIterator methods **/
|
||||
///@{
|
||||
/** RTTI: unique id# for actual runtime *data* representation **/
|
||||
virtual int32_t _typeseq() const noexcept = 0;
|
||||
virtual typeseq _typeseq() const noexcept = 0;
|
||||
/** retrieve AllocInfo for current iterator position
|
||||
**/
|
||||
virtual AllocInfo deref(Copaque d) const noexcept = 0;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include "AllocInfo.hpp"
|
||||
//#include "AllocIterator.hpp"
|
||||
#include "AllocRange.hpp"
|
||||
#include "typeseq.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
#include <xo/facet/facet_implementation.hpp>
|
||||
#include <xo/facet/typeseq.hpp>
|
||||
|
|
@ -40,6 +41,8 @@ namespace xo {
|
|||
using header_type = std::uint64_t;
|
||||
/** iterator range. These are forward iterators over allocs **/
|
||||
using range_type = AllocRange;
|
||||
/** sequence number identifying a datatype **/
|
||||
using typeseq = xo::facet::typeseq;
|
||||
///@}
|
||||
|
||||
/*
|
||||
|
|
@ -58,7 +61,7 @@ namespace xo {
|
|||
///@{
|
||||
|
||||
/** RTTI: unique id# for actual runtime data representation **/
|
||||
virtual int32_t _typeseq() const noexcept = 0;
|
||||
virtual typeseq _typeseq() const noexcept = 0;
|
||||
/** optional name for allocator @p d .
|
||||
* Allows labeling allocators, for diagnostics/instrumentation.
|
||||
**/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/** @file IAllocIter_Any.hpp
|
||||
/** @file IAllocIterator_Any.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
|
@ -20,10 +20,12 @@ namespace xo {
|
|||
* @brief AllocIterator implementation for empty variant instance
|
||||
**/
|
||||
struct IAllocIterator_Any : public AAllocIterator {
|
||||
using typeseq = xo::facet::typeseq;
|
||||
|
||||
const AAllocIterator * iface() const { return std::launder(this); }
|
||||
|
||||
// from AAllocIterator
|
||||
int32_t _typeseq() const noexcept override { return s_typeseq; }
|
||||
typeseq _typeseq() const noexcept override { return s_typeseq; }
|
||||
|
||||
// const methods
|
||||
[[noreturn]] AllocInfo deref(Copaque) const noexcept override { _fatal(); }
|
||||
|
|
@ -37,10 +39,10 @@ namespace xo {
|
|||
[[noreturn]] static void _fatal();
|
||||
|
||||
public:
|
||||
static int32_t s_typeseq;
|
||||
static typeseq s_typeseq;
|
||||
static bool _valid;
|
||||
};
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IAllocIter_Any.hpp */
|
||||
/* end IAllocIterator_Any.hpp */
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ namespace xo {
|
|||
typename IAllocIterator_DRepr>
|
||||
struct IAllocIterator_Xfer : public AAllocIterator {
|
||||
using Impl = IAllocIterator_DRepr;
|
||||
using typeseq = xo::facet::typeseq;
|
||||
|
||||
static const DRepr & _dcast(Copaque d) { return *(const DRepr *)d; }
|
||||
static DRepr & _dcast(Opaque d) { return *(DRepr *)d; }
|
||||
|
|
@ -26,7 +27,7 @@ namespace xo {
|
|||
|
||||
// const methods
|
||||
|
||||
int32_t _typeseq() const noexcept override { return s_typeseq; }
|
||||
typeseq _typeseq() const noexcept override { return s_typeseq; }
|
||||
AllocInfo deref(Copaque d)
|
||||
const noexcept override { return I::deref(_dcast(d)); }
|
||||
cmpresult compare(Copaque d,
|
||||
|
|
@ -42,12 +43,12 @@ namespace xo {
|
|||
using I = Impl;
|
||||
|
||||
public:
|
||||
static int32_t s_typeseq;
|
||||
static typeseq s_typeseq;
|
||||
static bool _valid;
|
||||
};
|
||||
|
||||
template <typename DRepr, typename IAllocIterator_DRepr>
|
||||
int32_t
|
||||
xo::facet::typeseq
|
||||
IAllocIterator_Xfer<DRepr, IAllocIterator_DRepr>::s_typeseq
|
||||
= facet::typeseq::id<DRepr>();
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "AAllocator.hpp"
|
||||
#include "AllocIterator.hpp"
|
||||
#include "typeseq.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
|
||||
namespace xo {
|
||||
|
|
@ -30,7 +31,7 @@ namespace xo {
|
|||
const AAllocator * iface() const { return std::launder(this); }
|
||||
|
||||
// from AAllocator
|
||||
int32_t _typeseq() const noexcept override { return s_typeseq; }
|
||||
typeseq _typeseq() const noexcept override { return s_typeseq; }
|
||||
|
||||
// const methods
|
||||
[[noreturn]] std::string_view name(Copaque) const noexcept override { _fatal(); }
|
||||
|
|
@ -58,7 +59,7 @@ namespace xo {
|
|||
[[noreturn]] static void _fatal();
|
||||
|
||||
public:
|
||||
static int32_t s_typeseq;
|
||||
static typeseq s_typeseq;
|
||||
static bool _valid;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ namespace xo {
|
|||
using Impl = IAllocator_DRepr;
|
||||
using size_type = AAllocator::size_type;
|
||||
using value_type = AAllocator::value_type;
|
||||
using typeseq = AAllocator::typeseq;
|
||||
///@}
|
||||
|
||||
/** @defgroup mm-allocator-xfer-methods IAllocator_Xfer methods **/
|
||||
|
|
@ -38,7 +39,7 @@ namespace xo {
|
|||
// const methods
|
||||
|
||||
/** return typeseq for @tparam DRepr **/
|
||||
int32_t _typeseq() const noexcept override { return s_typeseq; }
|
||||
typeseq _typeseq() const noexcept override { return s_typeseq; }
|
||||
std::string_view name(Copaque d) const noexcept override { return I::name(_dcast(d)); }
|
||||
size_type reserved(Copaque d) const noexcept override { return I::reserved(_dcast(d)); }
|
||||
size_type size(Copaque d) const noexcept override { return I::size(_dcast(d)); }
|
||||
|
|
@ -75,12 +76,12 @@ namespace xo {
|
|||
using I = Impl;
|
||||
|
||||
public:
|
||||
static int32_t s_typeseq;
|
||||
static xo::facet::typeseq s_typeseq;
|
||||
static bool _valid;
|
||||
};
|
||||
|
||||
template <typename DRepr, typename IAllocator_DRepr>
|
||||
int32_t
|
||||
xo::facet::typeseq
|
||||
IAllocator_Xfer<DRepr, IAllocator_DRepr>::s_typeseq = facet::typeseq::id<DRepr>();
|
||||
|
||||
template <typename DRepr, typename IAllocator_DRepr>
|
||||
|
|
|
|||
|
|
@ -17,11 +17,12 @@ namespace xo {
|
|||
public:
|
||||
using ObjectType = Object;
|
||||
using DataPtr = Object::DataPtr;
|
||||
using typeseq = xo::facet::typeseq;
|
||||
|
||||
RAllocIterator() {}
|
||||
RAllocIterator(Object::DataPtr data) : Object{std::move(data)} {}
|
||||
|
||||
int32_t _typeseq() const noexcept { return O::iface()->_typeseq(); }
|
||||
typeseq _typeseq() const noexcept { return O::iface()->_typeseq(); }
|
||||
AllocInfo deref() const noexcept { return O::iface()->deref(O::data()); }
|
||||
cmpresult compare(const obj<AAllocIterator> & other) const noexcept {
|
||||
return O::iface()->compare(O::data(), other); }
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ namespace xo {
|
|||
public:
|
||||
using ObjectType = Object;
|
||||
using DataPtr = Object::DataPtr;
|
||||
using typeseq = xo::facet::typeseq;
|
||||
using size_type = std::size_t;
|
||||
using value_type = std::byte *;
|
||||
using range_type = AAllocator::range_type;
|
||||
|
|
@ -27,7 +28,7 @@ namespace xo {
|
|||
RAllocator() {}
|
||||
RAllocator(Object::DataPtr data) : Object{std::move(data)} {}
|
||||
|
||||
int32_t _typeseq() const noexcept { return O::iface()->_typeseq(); }
|
||||
typeseq _typeseq() const noexcept { return O::iface()->_typeseq(); }
|
||||
std::string_view name() const noexcept { return O::iface()->name(O::data()); }
|
||||
size_type reserved() const noexcept { return O::iface()->reserved(O::data()); }
|
||||
size_type size() const noexcept { return O::iface()->size(O::data()); }
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace xo {
|
|||
/** optional name, for diagnostics **/
|
||||
std::string name_;
|
||||
/** desired arena size -- hard max = reserved virtual memory **/
|
||||
std::size_t size_;
|
||||
std::size_t size_ = 0;
|
||||
/** hugepage size -- using huge pages relieves some TLB pressure
|
||||
* (provided you use their full extent :)
|
||||
**/
|
||||
|
|
|
|||
|
|
@ -46,14 +46,13 @@ namespace xo {
|
|||
// end of hugeppage-aligned range starting at aligned_base
|
||||
byte * aligned_hi = aligned_base + target_z;
|
||||
|
||||
#ifdef NOT_YET
|
||||
log && log("acquired memory [lo,hi) using mmap",
|
||||
xtag("lo", base),
|
||||
xtag("aligned_lo", aligned_base),
|
||||
xtag("req_z", req_z),
|
||||
xtag("target_z", target_z),
|
||||
xtag("hi", (byte *)(base) + z));
|
||||
#endif
|
||||
|
||||
xtag("aligned_hi", aligned_hi),
|
||||
xtag("hi", hi));
|
||||
|
||||
// 3. assess mmap success
|
||||
{
|
||||
|
|
@ -109,7 +108,7 @@ namespace xo {
|
|||
DArena
|
||||
DArena::map(const ArenaConfig & cfg)
|
||||
{
|
||||
//scope log(XO_DEBUG(debug_flag), xtag("name", name));
|
||||
scope log(XO_DEBUG(true));
|
||||
|
||||
/* vm page size. 4KB, probably */
|
||||
size_t page_z = getpagesize();
|
||||
|
|
@ -122,6 +121,9 @@ namespace xo {
|
|||
*/
|
||||
size_t align_z = (enable_hugepage_flag ? cfg.hugepage_z_ : page_z);
|
||||
|
||||
log && log(xtag("page_z", page_z),
|
||||
xtag("align_z", align_z));
|
||||
|
||||
auto [lo, hi] = map_aligned_range(cfg.size_,
|
||||
align_z,
|
||||
enable_hugepage_flag);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace xo {
|
|||
std::terminate();
|
||||
}
|
||||
|
||||
int32_t
|
||||
typeseq
|
||||
IAllocIterator_Any::s_typeseq = typeseq::id<DVariantPlaceholder>();
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace xo {
|
|||
std::terminate();
|
||||
}
|
||||
|
||||
int32_t
|
||||
typeseq
|
||||
IAllocator_Any::s_typeseq = typeseq::id<DVariantPlaceholder>();
|
||||
|
||||
bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue