diff options
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/shed/gc/mark-and-sweep/gc.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/runtime/src/shed/gc/mark-and-sweep/gc.c b/runtime/src/shed/gc/mark-and-sweep/gc.c index c3ff8298..02759596 100644 --- a/runtime/src/shed/gc/mark-and-sweep/gc.c +++ b/runtime/src/shed/gc/mark-and-sweep/gc.c @@ -46,9 +46,20 @@ void shed__runtime__gc_init(void) { // == Allocation == +const int collect_interval = SHED_GC_COLLECT_INTERVAL; + +int calls_until_next_collect = collect_interval; + struct ShedGcObjectHeader* first = NULL; void* shed__runtime__gc_alloc(size_t size, uint32_t runtime_type_tag) { + if (calls_until_next_collect == 0) { + calls_until_next_collect = collect_interval; + shed__runtime__gc_collect(); + } else { + calls_until_next_collect--; + } + struct ShedGcObjectHeader* object = malloc(size); object->next = first; object->mark = 0; @@ -86,20 +97,10 @@ void sweep() { } } -const int collect_interval = SHED_GC_COLLECT_INTERVAL; - -int calls_until_next_collect = collect_interval; - void shed__runtime__gc_collect(void) { - if (calls_until_next_collect == 0) { - calls_until_next_collect = collect_interval; - - alternate_mark_value(); + alternate_mark_value(); - mark_reachable(); + mark_reachable(); - sweep(); - } else { - calls_until_next_collect--; - } + sweep(); } |
