coroutines: only attempt to add/remove roots when GC is on.

This commit is contained in:
Joe Conigliaro 2023-10-27 20:13:36 +11:00
parent f7058978a5
commit 77d45b1798
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1

View File

@ -25,13 +25,17 @@ fn init() {
alloc := fn (_ voidptr, stack_size int) voidptr { alloc := fn (_ voidptr, stack_size int) voidptr {
unsafe { unsafe {
stack_ptr := malloc(stack_size) stack_ptr := malloc(stack_size)
C.GC_add_roots(stack_ptr, charptr(stack_ptr) + stack_size) $if gcboehm {
C.GC_add_roots(stack_ptr, charptr(stack_ptr) + stack_size)
}
return stack_ptr return stack_ptr
} }
} }
dealloc := fn (_ voidptr, stack_ptr voidptr, stack_size int) { dealloc := fn (_ voidptr, stack_ptr voidptr, stack_size int) {
unsafe { unsafe {
C.GC_remove_roots(stack_ptr, charptr(stack_ptr) + stack_size) $if gcboehm {
C.GC_remove_roots(stack_ptr, charptr(stack_ptr) + stack_size)
}
free(stack_ptr) free(stack_ptr)
} }
} }