1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-24 09:17:17 +00:00
janet/gc.h

42 lines
1.2 KiB
C
Raw Normal View History

2017-02-09 20:02:59 +00:00
#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 */