aboutsummaryrefslogtreecommitdiff
path: root/source/gc.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/gc.c')
-rw-r--r--source/gc.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/source/gc.c b/source/gc.c
index 6db368c..07247f7 100644
--- a/source/gc.c
+++ b/source/gc.c
@@ -14,6 +14,7 @@ kpl_object_gc *kpl_gc_new(kpl_thread *thread, kpl_interface *interface, int32_t
kpl_memory_allocator_return(&thread->memory_allocator, obj);
return NULL;
}
+ obj_gc->object_flags = KPL_OBJECT_FLAGS_EMPTY;
obj_gc->gc_prev = obj_gc->gc_next = NULL;
__atomic_clear(&obj_gc->gc_mark, __ATOMIC_RELAXED);
obj_gc->class.interface = interface;
@@ -44,6 +45,13 @@ extern inline void kpl_gc_mark(kpl_object_gc *object_gc);
extern inline void kpl_gc_prepare_sweep(kpl_gc *gc);
+#define KPL_OBJECT_GC_FLAGS_NO_SWEEP_MASK (KPL_OBJECT_FLAGS_IO_PENDING | KPL_OBJECT_FLAGS_GC_PERSIST)
+
+static bool kpl_gc_object_is_alive(kpl_object_gc *object_gc) {
+ return object_gc->gc_mark ||
+ ((kpl_object*) object_gc->class.value.ptr)->object_flags & KPL_OBJECT_GC_FLAGS_NO_SWEEP_MASK;
+}
+
void kpl_gc_sweep(kpl_thread *thread) {
if (!thread->gc.gc_mark_head)
return;
@@ -51,7 +59,7 @@ void kpl_gc_sweep(kpl_thread *thread) {
while (mark_head) {
kpl_object_gc *tmp = mark_head;
mark_head = mark_head->gc_next;
- if (tmp->gc_mark) {
+ if (kpl_gc_object_is_alive(tmp)) {
__atomic_clear(&tmp->gc_mark, __ATOMIC_RELAXED);
mark_tail = tmp;
} else