diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-05-24 10:13:42 +0200 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-05-24 10:13:42 +0200 |
commit | a6d312ccb942b50287777fc22dc69de926ea3412 (patch) | |
tree | 0acabef2e78a97e7cd1742b9d98acb2a1b496e72 /system/include/gc.h | |
parent | c3570e254952ba0593038993674473e900ada9e0 (diff) | |
parent | b7ce870dd4b1352e308e212e77cd6161c1ec904e (diff) |
Merge branch 'master' into llvmsvn
Diffstat (limited to 'system/include/gc.h')
-rw-r--r-- | system/include/gc.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/system/include/gc.h b/system/include/gc.h new file mode 100644 index 00000000..996bc9ec --- /dev/null +++ b/system/include/gc.h @@ -0,0 +1,50 @@ +/* + * Boehm-compatible GC API + */ + +#include <stdlib.h> + +#ifdef __cplusplus +extern "C" { +#endif + +void __attribute__((used)) __GC_KEEPALIVE__() { + // Force inclusion of necessary dlmalloc functions + static int times = 1; + void *x = malloc(times); + free(x); + x = calloc(1, times); + free(x); + x = calloc(times, 1); + free(x); + times++; +} + +/* Initialize. */ +void GC_INIT(); + +/* Allocate memory. Cleared to 0 to erase all pointers. */ +void *GC_MALLOC(int bytes); + +/* Allocate memory for an object that the user promises will not contain pointers. */ +void *GC_MALLOC_ATOMIC(int bytes); + +/* Explicitly deallocate an object. Dangerous as it forces a free and does not check if the object is reffed. */ +void GC_FREE(void *ptr); + +/* Register a finalizer. func(ptr, arg) will be called. The old values are saved in old_func, old_arg */ +void GC_REGISTER_FINALIZER_NO_ORDER(void *ptr, void (*func)(void *, void *), void *arg, + void *(*old_func)(void *, void *), void *old_arg); + +/* Non-Boehm additions */ + +/* Call this once per frame or such, it will collect if necessary */ +void GC_MAYBE_COLLECT(); + +/* Forces a GC. Mainly useful for testing, but call it if you know a good time to GC in your app. */ +void GC_FORCE_COLLECT(); + +#ifdef __cplusplus +} +#endif + |