xo-imgui: ex2: animate GC copy step

This commit is contained in:
Roland Conybeare 2025-08-23 10:47:52 -04:00
commit d751093a87
3 changed files with 28 additions and 7 deletions

View file

@ -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..

View file

@ -7,6 +7,7 @@
#include <ostream>
#include <cstdint>
#include <cassert>
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*/

View file

@ -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*/