diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-03-19 18:39:42 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-03-19 18:39:42 +0000 |
| commit | a9a3c3a50b270e21180898d458597a4abfb7804b (patch) | |
| tree | 0c4a8843416f4aaee1ff7aef151f2d168fbc1046 /runtime/src | |
| parent | 3b7a25939f6117ab11084a448e591ffad5380874 (diff) | |
Call GC init once
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/shed/gc.h | 8 | ||||
| -rw-r--r-- | runtime/src/shed/gc/bump/gc.c | 13 | ||||
| -rw-r--r-- | runtime/src/shed/gc/mark-and-sweep/gc.c | 7 |
3 files changed, 21 insertions, 7 deletions
diff --git a/runtime/src/shed/gc.h b/runtime/src/shed/gc.h index ba1c98a4..70932148 100644 --- a/runtime/src/shed/gc.h +++ b/runtime/src/shed/gc.h @@ -36,8 +36,16 @@ extern struct ShedGcObjectHeader* shed__runtime__gc_root_stack[]; void shed__runtime__gc_push_root_gc_object(struct ShedGcObjectHeader* gc_root); +// == Initialization == + +void shed__runtime__gc_init(void); + // == Allocation == void* shed__runtime__gc_alloc(size_t size, uint32_t runtime_type_tag); +// == Collection == + +void shed__runtime__gc_collect(void); + #endif diff --git a/runtime/src/shed/gc/bump/gc.c b/runtime/src/shed/gc/bump/gc.c index e61e5d89..298fd3a6 100644 --- a/runtime/src/shed/gc/bump/gc.c +++ b/runtime/src/shed/gc/bump/gc.c @@ -8,6 +8,8 @@ void* ptr = NULL; intptr_t remaining = 0; +// == Initialization == + void shed__runtime__gc_init(void) { ptr = sbrk(0); @@ -21,12 +23,9 @@ void shed__runtime__gc_init(void) { } } -void* shed__runtime__gc_alloc(size_t size, uint32_t runtime_type_tag) { - // TODO: call init (once) from generated code - if (ptr == NULL) { - shed__runtime__gc_init(); - } +// == Allocation == +void* shed__runtime__gc_alloc(size_t size, uint32_t runtime_type_tag) { if (size % sizeof(PatioInt) != 0) { size = size + (sizeof(PatioInt) - size % sizeof(PatioInt)); } @@ -49,5 +48,7 @@ void* shed__runtime__gc_alloc(size_t size, uint32_t runtime_type_tag) { return object; } -void shed__runtime__gc_collect() { +// == Collection == + +void shed__runtime__gc_collect(void) { } diff --git a/runtime/src/shed/gc/mark-and-sweep/gc.c b/runtime/src/shed/gc/mark-and-sweep/gc.c index 68f9ad8e..c3ff8298 100644 --- a/runtime/src/shed/gc/mark-and-sweep/gc.c +++ b/runtime/src/shed/gc/mark-and-sweep/gc.c @@ -39,6 +39,11 @@ void mark(struct ShedGcObjectHeader* object) { } } +// == Initialization == + +void shed__runtime__gc_init(void) { +} + // == Allocation == struct ShedGcObjectHeader* first = NULL; @@ -85,7 +90,7 @@ const int collect_interval = SHED_GC_COLLECT_INTERVAL; int calls_until_next_collect = collect_interval; -void shed__runtime__gc_collect() { +void shed__runtime__gc_collect(void) { if (calls_until_next_collect == 0) { calls_until_next_collect = collect_interval; |
