2021-03-20 16:16:36 +03:00
|
|
|
module builtin
|
|
|
|
|
|
|
|
#define GC_THREADS 1
|
|
|
|
|
2021-03-21 03:01:21 +03:00
|
|
|
$if windows {
|
|
|
|
#flag -I@VROOT/thirdparty/libgc/include
|
|
|
|
#flag -L@VROOT/thirdparty/libgc
|
|
|
|
}
|
2021-03-25 08:28:30 +03:00
|
|
|
$if macos {
|
|
|
|
#pkgconfig bdw-gc
|
|
|
|
}
|
2021-03-25 18:52:33 +03:00
|
|
|
$if gcboehm_leak ? {
|
|
|
|
#define GC_DEBUG
|
|
|
|
}
|
2021-03-20 16:16:36 +03:00
|
|
|
#include <gc.h>
|
|
|
|
|
2021-03-25 08:28:30 +03:00
|
|
|
#flag -lgc
|
2021-03-20 16:16:36 +03:00
|
|
|
|
2021-03-25 18:52:33 +03:00
|
|
|
// replacements for `malloc()/calloc()`, `realloc()` and `free()`
|
|
|
|
// for use with Boehm-GC
|
|
|
|
// Do not use them manually. They are automatically chosen when
|
|
|
|
// compiled with `-gc boehm` or `-gc boehm_leak`.
|
2021-03-20 16:16:36 +03:00
|
|
|
fn C.GC_MALLOC(n size_t) voidptr
|
|
|
|
|
2021-03-26 17:44:45 +03:00
|
|
|
fn C.GC_MALLOC_UNCOLLECTABLE(n size_t) voidptr
|
|
|
|
|
2021-03-20 16:16:36 +03:00
|
|
|
fn C.GC_REALLOC(ptr voidptr, n size_t) voidptr
|
|
|
|
|
|
|
|
fn C.GC_FREE(ptr voidptr)
|
2021-03-21 05:31:06 +03:00
|
|
|
|
2021-03-25 18:52:33 +03:00
|
|
|
// explicitely perform garbage collection now! Garbage collections
|
|
|
|
// are done automatically when needed, so this function is hardly needed
|
2021-03-21 05:31:06 +03:00
|
|
|
fn C.GC_gcollect()
|
2021-03-25 18:52:33 +03:00
|
|
|
|
|
|
|
// functions to temporarily suspend/resume garbage collection
|
|
|
|
fn C.GC_disable()
|
|
|
|
|
|
|
|
fn C.GC_enable()
|
|
|
|
|
|
|
|
// returns non-zero if GC is disabled
|
|
|
|
fn C.GC_is_disabled() int
|
|
|
|
|
|
|
|
// for leak detection it is advisable to do explicit garbage collections
|
|
|
|
pub fn gc_check_leaks() {
|
|
|
|
$if gcboehm_leak ? {
|
|
|
|
C.GC_gcollect()
|
|
|
|
}
|
|
|
|
}
|