Make small adjustments to GC functions.
This commit is contained in:
16
src/gc.c
16
src/gc.c
@@ -6,11 +6,11 @@ void libab_gc_list_init(libab_gc_list* list) {
|
||||
list->head = list->tail = NULL;
|
||||
}
|
||||
|
||||
void _gc_count_visit(libab_ref_count* ref, libab_visitor_function_ptr func, void* data) {
|
||||
void _gc_count_visit_children(libab_ref_count* ref, libab_visitor_function_ptr func, void* data) {
|
||||
if(ref->strong && ref->visit_children) ref->visit_children(ref->data, func, data);
|
||||
}
|
||||
void libab_gc_visit(libab_ref* ref, libab_visitor_function_ptr func, void* data) {
|
||||
_gc_count_visit(ref->count, func, data);
|
||||
void libab_gc_visit_children(libab_ref* ref, libab_visitor_function_ptr func, void* data) {
|
||||
_gc_count_visit_children(ref->count, func, data);
|
||||
}
|
||||
|
||||
void _libab_gc_list_append(libab_gc_list* list,
|
||||
@@ -35,14 +35,14 @@ void libab_gc_add(libab_ref* ref,
|
||||
}
|
||||
|
||||
void _gc_decrement(libab_ref_count* count, void* data) {
|
||||
count->gc--;
|
||||
if(count->visit_children) count->gc--;
|
||||
}
|
||||
void _gc_save(libab_ref_count* count, void* data) {
|
||||
libab_gc_list* list = data;
|
||||
if(count->gc != -1) {
|
||||
if(count->visit_children && count->gc != -1) {
|
||||
count->gc = -1;
|
||||
_libab_gc_list_append(list, count);
|
||||
_gc_count_visit(count, _gc_save, data);
|
||||
_gc_count_visit_children(count, _gc_save, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,12 +58,12 @@ void libab_gc_run(libab_gc_list* list) {
|
||||
|
||||
head = list->head;
|
||||
while(head) {
|
||||
_gc_count_visit(head, _gc_decrement, NULL);
|
||||
_gc_count_visit_children(head, _gc_decrement, NULL);
|
||||
}
|
||||
|
||||
head = list->head;
|
||||
while(head) {
|
||||
_gc_count_visit(head, _gc_save, &safe);
|
||||
_gc_count_visit_children(head, _gc_save, &safe);
|
||||
}
|
||||
|
||||
head = list->head;
|
||||
|
||||
@@ -11,6 +11,7 @@ libab_result libab_ref_new(libab_ref* ref, void* data,
|
||||
ref->count->data = data;
|
||||
ref->count->strong = ref->count->weak = 1;
|
||||
ref->count->free_func = free_func;
|
||||
ref->count->visit_children = NULL;
|
||||
ref->count->prev = NULL;
|
||||
ref->count->next = NULL;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user