xo-alloc2: DX1CollectorIterator infra [WIP]
This commit is contained in:
parent
59c0311ed7
commit
bf27314688
30 changed files with 1041 additions and 176 deletions
|
|
@ -145,6 +145,8 @@ namespace xo {
|
|||
generation gc_upto_;
|
||||
};
|
||||
|
||||
struct DX1CollectorIterator;
|
||||
|
||||
// ----- DX1Collector -----
|
||||
|
||||
struct DX1Collector {
|
||||
|
|
@ -212,6 +214,15 @@ namespace xo {
|
|||
/** Retreive bookkeeping info for allocation at @p mem. **/
|
||||
AllocInfo alloc_info(value_type mem) noexcept;
|
||||
|
||||
// ----- iteration -----
|
||||
|
||||
/** alloc iterator at begin position **/
|
||||
DX1CollectorIterator begin() const noexcept;
|
||||
/** alloc iterator at end position
|
||||
* (valid, but cannot be dereferenced)
|
||||
**/
|
||||
DX1CollectorIterator end() const noexcept;
|
||||
|
||||
// ----- book-keeping -----
|
||||
|
||||
/** reverse to-space and from-space roles for generation g **/
|
||||
|
|
|
|||
90
include/xo/alloc2/gc/DX1CollectorIterator.hpp
Normal file
90
include/xo/alloc2/gc/DX1CollectorIterator.hpp
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/** @file DX1CollectorIterator.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "alloc/AllocInfo.hpp"
|
||||
#include "gc/generation.hpp"
|
||||
#include "arena/DArenaIterator.hpp"
|
||||
#include "cmpresult.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
struct DX1Collector;
|
||||
|
||||
/** @class DX1CollectorIterator
|
||||
* @brief Representation for alloc iterator over X1 collector
|
||||
*
|
||||
* Will iterate across all allocs in all generations
|
||||
**/
|
||||
struct DX1CollectorIterator {
|
||||
DX1CollectorIterator() = default;
|
||||
DX1CollectorIterator(const DX1Collector * gc,
|
||||
generation gen_ix,
|
||||
generation gen_hi,
|
||||
DArenaIterator arena_ix,
|
||||
DArenaIterator arena_hi);
|
||||
|
||||
/** Invalid iterator. Does not compare equal to anything, including itself **/
|
||||
static DX1CollectorIterator invalid() { return DX1CollectorIterator(); }
|
||||
/** Create iterator pointing to the beginning of @p gc.
|
||||
* Iterator cannot modify payload memory
|
||||
**/
|
||||
static DX1CollectorIterator begin(DX1Collector * gc);
|
||||
/** Create iterator pointing to the end of @p gc.
|
||||
* Iterator cannot modify payload memory.
|
||||
**/
|
||||
static DX1CollectorIterator end(DX1Collector * gc);
|
||||
|
||||
/** true if iterator is invalid. invalid iterators are not comparable **/
|
||||
bool is_valid() const noexcept { return (gc_ != nullptr); }
|
||||
bool is_invalid() const noexcept { return !is_valid(); }
|
||||
|
||||
/** fetch contents at current iterator position **/
|
||||
AllocInfo deref() const noexcept;
|
||||
/** compare two iterators. To be comparable,
|
||||
* iterators must refer to the same collector
|
||||
**/
|
||||
cmpresult compare(const DX1CollectorIterator & other) const noexcept;
|
||||
/** advance iterator to next allocation **/
|
||||
void next() noexcept;
|
||||
|
||||
/** for *ix synonym for ix.deref() **/
|
||||
AllocInfo operator*() const noexcept { return this->deref(); }
|
||||
|
||||
private:
|
||||
/** if non-empty, normalize to state with arena_ix_ != arena_hi_ **/
|
||||
void normalize() noexcept;
|
||||
|
||||
private:
|
||||
/** Iterator visits allocations from this collector **/
|
||||
const DX1Collector * gc_ = nullptr;
|
||||
/** Iterating over generations in [@p gen_ix_, @p gen_hi_).
|
||||
* Current position is within arena for @p gen_ix_ to-space,
|
||||
* Provided @p gen_ix_ < @p gen_hi_
|
||||
**/
|
||||
generation gen_ix_;
|
||||
generation gen_hi_;
|
||||
/** Iterating over allocs in [@p arena_ix_, @p arena_hi_).
|
||||
* Current position is at @p arena_ix_
|
||||
**/
|
||||
DArenaIterator arena_ix_;
|
||||
DArenaIterator arena_hi_;
|
||||
};
|
||||
|
||||
inline bool
|
||||
operator==(const DX1CollectorIterator & x, const DX1CollectorIterator & y) {
|
||||
return x.compare(y).is_equal();
|
||||
}
|
||||
|
||||
inline bool
|
||||
operator!=(const DX1CollectorIterator & x, const DX1CollectorIterator & y) {
|
||||
return !x.compare(y).is_equal();
|
||||
}
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DX1CollectorIterator.hpp */
|
||||
36
include/xo/alloc2/gc/IAllocIterator_DX1CollectorIterator.hpp
Normal file
36
include/xo/alloc2/gc/IAllocIterator_DX1CollectorIterator.hpp
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/** @file IAllocIterator_DX1Collector.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "alloc/IAllocIterator_Xfer.hpp"
|
||||
#include "gc/DX1CollectorIterator.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm { struct IAllocIterator_DX1CollectorIterator; }
|
||||
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::mm::AAllocIterator,
|
||||
xo::mm::DX1CollectorIterator> {
|
||||
using ImplType = xo::mm::IAllocIterator_Xfer<xo::mm::DX1CollectorIterator,
|
||||
xo::mm::IAllocIterator_DX1CollectorIterator>;
|
||||
};
|
||||
}
|
||||
|
||||
namespace mm {
|
||||
/** @class IAllocIterator_DX1Collector
|
||||
* @brief alloc iteration for the DX1Collector allocator
|
||||
**/
|
||||
struct IAllocIterator_DX1CollectorIterator {
|
||||
static AllocInfo deref(const DX1CollectorIterator &) noexcept;
|
||||
static cmpresult compare(const DX1CollectorIterator &,
|
||||
const obj<AAllocIterator> & other) noexcept;
|
||||
static void next(DX1CollectorIterator &) noexcept;
|
||||
};
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IAllocIterator_DX1Collector.hpp */
|
||||
|
|
@ -19,6 +19,7 @@ namespace xo {
|
|||
struct generation {
|
||||
using value_type = std::uint32_t;
|
||||
|
||||
constexpr generation() = default;
|
||||
explicit constexpr generation(value_type x) : value_{x} {}
|
||||
|
||||
static generation nursery() { return generation{0}; }
|
||||
|
|
@ -27,7 +28,7 @@ namespace xo {
|
|||
|
||||
generation & operator++() { ++value_; return *this; }
|
||||
|
||||
std::uint32_t value_;
|
||||
std::uint32_t value_ = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue