1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-26 07:03:16 +00:00
janet/gc.h
2017-02-09 15:02:59 -05:00

42 lines
1.2 KiB
C

#ifndef GC_H_N8L3U4KK
#define GC_H_N8L3U4KK
#include "datatypes.h"
/* Initialize a GC */
void GCInit(GC * gc, uint32_t memoryInterval);
/* Iterate over all allocated memory, and frees memory that is not
* marked as reachable */
void GCSweep(GC * gc);
/* Do a depth first search of the variables and mark all reachable memory.
* Root variables are just everyting in the stack. */
void GCMark(GC * gc, Value * x);
/* Mark some raw memory as reachable */
void GCMarkMemory(GC * gc, void * memory);
/* Clean up all memory, including locked memory */
void GCClear(GC * gc);
/* Allocate some memory that is tracked for garbage collection */
void * GCAlloc(GC * gc, uint32_t size);
/* Allocate zeroed memory */
void * GCZalloc(GC * gc, uint32_t size);
/* Run a collection */
#define GCCollect(gc, root) \
(GCMark((gc), (root)), GCSweep(gc), (gc)->nextCollection = 0)
/* Check if a collection needs to be run */
#define GCNeedsCollect(gc) \
((gc)->nextCollection >= (gc)->memoryInterval)
/* Run a collection if enough memory has been allocated since last collection */
#define GCMaybeCollect(gc, root) \
(GCNeedsCollect(gc) ? GCCollect((gc), (root)) : 0)
#endif /* end of include guard: GC_H_N8L3U4KK */