diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-05-15 11:08:49 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-05-15 11:32:45 -0700 |
commit | 1cd225a385cabf5857054e88b1931f997953148f (patch) | |
tree | 546b68d3d22563dbca69e53551993ca6d2030463 /system | |
parent | c0f78411015b0f5330cca52e12a4109774f982b5 (diff) |
initial work on c++ gc support
Diffstat (limited to 'system')
-rw-r--r-- | system/include/gc.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/system/include/gc.h b/system/include/gc.h new file mode 100644 index 00000000..a4f7afbb --- /dev/null +++ b/system/include/gc.h @@ -0,0 +1,41 @@ +/* + * Boehm-compatible GC API + */ + +#ifdef __cplusplus +extern "C" { +#endif + +void __attribute__((used)) __GC_KEEPALIVE__() { + // Force inclusion of necessary dlmalloc functions + static times = 1; + void *x = malloc(times); + free(x); + x = calloc(times); + 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 *arg, + void *(*old_func)(), void *old_arg); + +/* Non-Boehm addition. Call this once per frame or such, it will collect if necessary */ +void GC_MAYBE_COLLECT(); + +#ifdef __cplusplus +} +#endif + |