1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-24 12:20:20 +02:00

Implement cooperative safepoint API

Fixes https://github.com/wingo/whippet/issues/9.
This commit is contained in:
Andy Wingo 2024-09-18 11:31:06 +02:00
parent 9f26dbb1fc
commit 8fba0e5322
11 changed files with 95 additions and 63 deletions

View file

@ -208,4 +208,24 @@ static inline void gc_write_barrier(struct gc_ref obj, size_t obj_size,
GC_API_ void gc_pin_object(struct gc_mutator *mut, struct gc_ref obj);
GC_API_ void gc_safepoint_slow(struct gc_mutator *mut) GC_NEVER_INLINE;
GC_API_ int* gc_safepoint_flag_loc(struct gc_mutator *mut);
static inline int gc_should_stop_for_safepoint(struct gc_mutator *mut) {
switch (gc_cooperative_safepoint_kind()) {
case GC_COOPERATIVE_SAFEPOINT_NONE:
return 0;
case GC_COOPERATIVE_SAFEPOINT_MUTATOR_FLAG:
case GC_COOPERATIVE_SAFEPOINT_HEAP_FLAG: {
return atomic_load_explicit(gc_safepoint_flag_loc(mut),
memory_order_relaxed);
}
default:
GC_CRASH();
}
}
static inline void gc_safepoint(struct gc_mutator *mut) {
if (GC_UNLIKELY(gc_should_stop_for_safepoint(mut)))
gc_safepoint_slow(mut);
}
#endif // GC_API_H_