Move GC code to separate source file.
This commit is contained in:
33
include/gc.h
Normal file
33
include/gc.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef LIBABACUS_GC_H
|
||||
#define LIBABACUS_GC_H
|
||||
|
||||
struct libab_ref_s;
|
||||
struct libab_ref_count_s;
|
||||
|
||||
/**
|
||||
* Struct used to create an interface
|
||||
* for a set of objects to be collected.
|
||||
*/
|
||||
struct libab_gc_list_s {
|
||||
/**
|
||||
* The head of the linked list.
|
||||
*/
|
||||
struct libab_ref_count_s* head;
|
||||
/**
|
||||
* The tail of the linked list.
|
||||
*/
|
||||
struct libab_ref_count_s* tail;
|
||||
};
|
||||
|
||||
typedef struct libab_gc_list_s libab_gc_list;
|
||||
typedef void (*libab_visitor_function_ptr)(struct libab_ref_count_s* , void*);
|
||||
typedef void (*libab_visit_function_ptr)(void*, libab_visitor_function_ptr, void*);
|
||||
|
||||
void libab_gc_list_init(libab_gc_list* list);
|
||||
void libab_gc_visit(struct libab_ref_s*, libab_visitor_function_ptr visitor, void*);
|
||||
void libab_gc_add(struct libab_ref_s* ref,
|
||||
libab_visit_function_ptr visit_children,
|
||||
libab_gc_list* list);
|
||||
void libab_gc_run(libab_gc_list* list);
|
||||
|
||||
#endif
|
||||
@@ -2,12 +2,7 @@
|
||||
#define LIBABACUS_REFCOUNT_H
|
||||
|
||||
#include "result.h"
|
||||
|
||||
struct libab_ref_s;
|
||||
struct libab_ref_count_s;
|
||||
|
||||
typedef void (*libab_visitor_function_ptr)(struct libab_ref_count_s* , void*);
|
||||
typedef void (*libab_visit_function_ptr)(void*, libab_visitor_function_ptr, void*);
|
||||
#include "gc.h"
|
||||
|
||||
/**
|
||||
* A struct for holding
|
||||
@@ -57,21 +52,6 @@ struct libab_ref_count_s {
|
||||
libab_visit_function_ptr visit_children;
|
||||
};
|
||||
|
||||
/**
|
||||
* Struct used to create an interface
|
||||
* for a set of objects to be collected.
|
||||
*/
|
||||
struct libab_ref_gc_list_s {
|
||||
/**
|
||||
* The head of the linked list.
|
||||
*/
|
||||
struct libab_ref_count_s* head;
|
||||
/**
|
||||
* The tail of the linked list.
|
||||
*/
|
||||
struct libab_ref_count_s* tail;
|
||||
};
|
||||
|
||||
/**
|
||||
* A reference to a value.
|
||||
*/
|
||||
@@ -93,7 +73,6 @@ struct libab_ref_s {
|
||||
|
||||
typedef struct libab_ref_s libab_ref;
|
||||
typedef struct libab_ref_count_s libab_ref_count;
|
||||
typedef struct libab_ref_gc_list_s libab_ref_gc_list;
|
||||
|
||||
/**
|
||||
* Creates a new referene, using the given data and free function.
|
||||
@@ -111,11 +90,6 @@ libab_result libab_ref_new(libab_ref* ref, void* data,
|
||||
* @param ref the reference to initialize with null.
|
||||
*/
|
||||
void libab_ref_null(libab_ref* ref);
|
||||
void libab_ref_gc_visit(libab_ref*, libab_visitor_function_ptr visitor, void*);
|
||||
void libab_ref_gc_add(libab_ref* ref,
|
||||
libab_visit_function_ptr visit_children,
|
||||
libab_ref_gc_list* list);
|
||||
void libab_ref_gc_run(libab_ref_gc_list* list);
|
||||
/**
|
||||
* Turns the given reference into a weak reference,
|
||||
* making it not keep the data allocated.
|
||||
|
||||
Reference in New Issue
Block a user