mirror of
https://github.com/bdwgc/bdwgc-rust.git
synced 2026-10-25 09:23:18 -06:00
impl. register_finalizer, force_collect (#248)
This commit is contained in:
1 parent
d7521be32f
commit
59fe9dfa47
1 file changed
+20
+20
@@ -26,6 +26,14 @@ extern "C" {
|
||||
fn GC_register_my_thread(stack_base: *const GcStackBase) -> c_int;
|
||||
fn GC_set_stackbottom(thread: *const c_void, stack_bottom: *const GcStackBase);
|
||||
fn GC_unregister_my_thread();
|
||||
fn GC_gcollect();
|
||||
fn GC_register_finalizer(
|
||||
obj: *const c_void,
|
||||
f: extern "C" fn(*mut c_void, *mut c_void),
|
||||
client_data: *const c_void,
|
||||
opt_old_f: *const c_void,
|
||||
opt_old_cd: *const c_void,
|
||||
) -> *mut c_void;
|
||||
}
|
||||
|
||||
pub struct Allocator;
|
||||
@@ -70,6 +78,18 @@ impl Allocator {
|
||||
pub unsafe fn unregister_current_thread() {
|
||||
GC_unregister_my_thread()
|
||||
}
|
||||
|
||||
pub fn force_collect() {
|
||||
unsafe { GC_gcollect() }
|
||||
}
|
||||
|
||||
pub unsafe fn register_finalizer(
|
||||
obj: *const c_void,
|
||||
f: extern "C" fn(*mut c_void, *mut c_void),
|
||||
client_data: *const c_void,
|
||||
) {
|
||||
GC_register_finalizer(obj, f, client_data, std::ptr::null(), std::ptr::null());
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl GlobalAlloc for Allocator {
|
||||
|
||||
Reference in new issue
Block a user