mirror of
https://github.com/bdwgc/bdwgc-rust.git
synced 2026-05-30 02:18:57 -06:00
impl. register_finalizer, force_collect (#248)
This commit is contained in:
20
src/lib.rs
20
src/lib.rs
@@ -26,6 +26,14 @@ extern "C" {
|
|||||||
fn GC_register_my_thread(stack_base: *const GcStackBase) -> c_int;
|
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_set_stackbottom(thread: *const c_void, stack_bottom: *const GcStackBase);
|
||||||
fn GC_unregister_my_thread();
|
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;
|
pub struct Allocator;
|
||||||
@@ -70,6 +78,18 @@ impl Allocator {
|
|||||||
pub unsafe fn unregister_current_thread() {
|
pub unsafe fn unregister_current_thread() {
|
||||||
GC_unregister_my_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 {
|
unsafe impl GlobalAlloc for Allocator {
|
||||||
|
|||||||
Reference in New Issue
Block a user