From d751093a87021e99ec655d0e29dd46d1801229d9 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 23 Aug 2025 10:47:52 -0400 Subject: [PATCH] xo-imgui: ex2: animate GC copy step --- include/xo/alloc/GC.hpp | 12 +++++++++--- include/xo/alloc/generation.hpp | 10 ++++++++++ src/alloc/GC.cpp | 13 +++++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/include/xo/alloc/GC.hpp b/include/xo/alloc/GC.hpp index 7c4f42c6..8ddb3e23 100644 --- a/include/xo/alloc/GC.hpp +++ b/include/xo/alloc/GC.hpp @@ -154,6 +154,8 @@ namespace xo { /** true iff GC permitted in current state **/ bool is_gc_enabled() const { return gc_enabled_ == 0; } + /** true iff GC has been requested **/ + bool is_gc_pending() const { return incr_gc_pending_ || full_gc_pending_; } /** true during (and only during) a GC cycle **/ bool gc_in_progress() const { return runstate_.in_progress(); } /** @return reserved size of Nursery to-space **/ @@ -223,10 +225,14 @@ namespace xo { * * GC is enabled when number of calls to @ref enable_gc is at least as large * as number of calls to @ref disable_gc. + * + * @return true iff GC performed **/ - void enable_gc(); - /** same as @c this->enable_gc() followed by @c this->disable_gc() **/ - void enable_gc_once(); + bool enable_gc(); + /** same as @c this->enable_gc() followed by @c this->disable_gc() + * @return true iff GC performed + **/ + bool enable_gc_once(); // inherited from IAlloc.. diff --git a/include/xo/alloc/generation.hpp b/include/xo/alloc/generation.hpp index 2ed89276..0acd943a 100644 --- a/include/xo/alloc/generation.hpp +++ b/include/xo/alloc/generation.hpp @@ -7,6 +7,7 @@ #include #include +#include namespace xo { namespace gc { @@ -31,6 +32,15 @@ namespace xo { not_found }; + inline generation valid_genresult2gen(generation_result x) { + assert(x != generation_result::not_found); + + if (x == generation_result::nursery) + return generation::nursery; + else + return generation::tenured; + } + } /*namespace gc*/ } /*namespace xo*/ diff --git a/src/alloc/GC.cpp b/src/alloc/GC.cpp index e6fb188f..200ac218 100644 --- a/src/alloc/GC.cpp +++ b/src/alloc/GC.cpp @@ -1233,21 +1233,26 @@ namespace xo { --gc_enabled_; } - void + bool GC::enable_gc() { ++gc_enabled_; if (gc_enabled_ == 0) { /* unblock gc */ - if (incr_gc_pending_) + if (incr_gc_pending_) { this->request_gc(full_gc_pending_ ? generation::tenured : generation::nursery); + return true; + } } + + return false; } - void + bool GC::enable_gc_once() { - this->enable_gc(); + bool retval = this->enable_gc(); this->disable_gc(); + return retval; } } /*namespace gc*/