From 6cd1327c5cf3c282b338769c807d32dfef48f107 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Sat, 1 Jun 2019 21:29:19 +0000 Subject: [PATCH] Replace disable/enable functions with lock/unlock --- examples/coroutines/src/main.rs | 4 ++-- examples/suspended_coroutines/src/main.rs | 8 ++++---- src/lib.rs | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/coroutines/src/main.rs b/examples/coroutines/src/main.rs index 86f730d..41ae7d8 100644 --- a/examples/coroutines/src/main.rs +++ b/examples/coroutines/src/main.rs @@ -10,12 +10,12 @@ static GLOBAL_ALLOCATOR: Allocator = Allocator; fn main() { unsafe { Allocator::initialize() } - Allocator::disable_gc(); + Allocator::lock(); let handle = Coroutine::spawn(move |_, _| { let bottom: u8 = 0; unsafe { Allocator::set_stack_bottom(&bottom) } - Allocator::enable_gc(); + Allocator::unlock(); loop { unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) }; diff --git a/examples/suspended_coroutines/src/main.rs b/examples/suspended_coroutines/src/main.rs index 3de197a..87d44f5 100644 --- a/examples/suspended_coroutines/src/main.rs +++ b/examples/suspended_coroutines/src/main.rs @@ -11,22 +11,22 @@ static GLOBAL_ALLOCATOR: Allocator = Allocator; fn main() { unsafe { Allocator::initialize() } - Allocator::disable_gc(); + Allocator::lock(); let mut handle = Coroutine::spawn(move |me, _| { let bottom: u8 = 0; unsafe { Allocator::set_stack_bottom(&bottom) } - Allocator::enable_gc(); + Allocator::unlock(); me.yield_with(42); unsafe { Allocator::set_stack_bottom(&bottom) } - Allocator::enable_gc(); + Allocator::unlock(); loop { unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) }; } }); - Allocator::disable_gc(); + Allocator::lock(); assert_eq!(handle.resume(0).unwrap(), 42); handle.resume(0).unwrap(); diff --git a/src/lib.rs b/src/lib.rs index cecaf61..5650ce6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,8 +20,8 @@ extern "C" { callback: unsafe extern "C" fn(*const c_void) -> *const c_void, client_data: *const c_void, ) -> *const c_void; - fn GC_disable() -> c_void; - fn GC_enable() -> c_void; + fn GC_alloc_lock() -> c_void; + fn GC_alloc_unlock() -> c_void; fn GC_free(ptr: *mut c_void); fn GC_get_stack_base(stack_base: *mut GcStackBase) -> c_int; fn GC_init() -> c_void; @@ -34,12 +34,12 @@ extern "C" { pub struct Allocator; impl Allocator { - pub fn disable_gc() { - unsafe { GC_disable() }; + pub fn lock() { + unsafe { GC_alloc_lock() }; } - pub fn enable_gc() { - unsafe { GC_enable() }; + pub fn unlock() { + unsafe { GC_alloc_unlock() }; } pub unsafe fn initialize() {