2018-08-11 01:40:30 -07:00
|
|
|
#ifndef LIBABACUS_GC_H
|
|
|
|
#define LIBABACUS_GC_H
|
|
|
|
|
2018-08-11 18:22:18 -07:00
|
|
|
#include "refcount.h"
|
|
|
|
#include "gc_functions.h"
|
2018-08-11 01:40:30 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Struct used to create an interface
|
|
|
|
* for a set of objects to be collected.
|
|
|
|
*/
|
|
|
|
struct libab_gc_list_s {
|
|
|
|
/**
|
2018-08-11 18:22:18 -07:00
|
|
|
* The head sentinel node.
|
2018-08-11 01:40:30 -07:00
|
|
|
*/
|
2018-08-11 18:22:18 -07:00
|
|
|
struct libab_ref_count_s head_sentinel;
|
2018-08-11 01:40:30 -07:00
|
|
|
/**
|
2018-08-11 18:22:18 -07:00
|
|
|
* The tail sentinel node.
|
2018-08-11 01:40:30 -07:00
|
|
|
*/
|
2018-08-11 18:22:18 -07:00
|
|
|
struct libab_ref_count_s tail_sentinel;
|
2018-08-11 01:40:30 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct libab_gc_list_s libab_gc_list;
|
|
|
|
|
2018-08-11 15:59:44 -07:00
|
|
|
/**
|
|
|
|
* Initializes a garbage collection tracking list.
|
|
|
|
* @param list the list to initialize.
|
|
|
|
*/
|
2018-08-11 01:40:30 -07:00
|
|
|
void libab_gc_list_init(libab_gc_list* list);
|
2018-08-11 15:59:44 -07:00
|
|
|
/**
|
|
|
|
* Visits the children of the current node, applying the given function to them.
|
|
|
|
* @param ref the reference whose children to visit.
|
|
|
|
* @param visitor the function to call for each child.
|
|
|
|
* @param data the data to pass to the visitor.
|
|
|
|
*/
|
2018-08-11 18:22:18 -07:00
|
|
|
void libab_gc_visit_children(struct libab_ref_s* ref, libab_visitor_function_ptr visitor, void* data);
|
2018-08-11 20:01:43 -07:00
|
|
|
/**
|
|
|
|
* Applies the given visitor function to this reference.
|
|
|
|
*/
|
|
|
|
void libab_gc_visit(struct libab_ref_s* ref, libab_visitor_function_ptr visitor, void* data);
|
2018-08-11 15:59:44 -07:00
|
|
|
/**
|
|
|
|
* Adds the given reference to the given garbage collection list,
|
|
|
|
* and specifies a function used to reach its children.
|
|
|
|
* @param ref the reference whose children to visit.
|
|
|
|
* @param visit_children the function used to reach the chilren of this reference.
|
|
|
|
* @param list the list to which to add the reference.
|
|
|
|
*/
|
2018-08-11 01:40:30 -07:00
|
|
|
void libab_gc_add(struct libab_ref_s* ref,
|
|
|
|
libab_visit_function_ptr visit_children,
|
|
|
|
libab_gc_list* list);
|
2018-08-11 15:59:44 -07:00
|
|
|
/**
|
|
|
|
* Performs garbage collection on a given list of container objects/
|
|
|
|
* @param list the list to run collection on.
|
|
|
|
*/
|
2018-08-11 01:40:30 -07:00
|
|
|
void libab_gc_run(libab_gc_list* list);
|
|
|
|
|
|
|
|
#endif
|