diff --git a/Cargo.lock b/Cargo.lock index c9726d4..54354b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,7 +2,7 @@ # It is not intended for manual editing. [[package]] name = "bdwgc-alloc" -version = "0.1.1" +version = "0.2.0" dependencies = [ "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index 3a621b3..66240e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bdwgc-alloc" description = "impl GlobalAlloc for bdwgc" -version = "0.1.1" +version = "0.2.0" authors = ["swgillespie ", "Yota Toyama "] repository = "https://github.com/raviqqe/bdwgc-rs" edition = "2018" diff --git a/examples/allocation_loop/Cargo.lock b/examples/allocation_loop/Cargo.lock index 45c13c6..1283123 100644 --- a/examples/allocation_loop/Cargo.lock +++ b/examples/allocation_loop/Cargo.lock @@ -4,12 +4,12 @@ name = "allocation_loop" version = "0.1.0" dependencies = [ - "bdwgc-alloc 0.1.1", + "bdwgc-alloc 0.2.0", ] [[package]] name = "bdwgc-alloc" -version = "0.1.1" +version = "0.2.0" dependencies = [ "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/examples/dynamic_threads/Cargo.lock b/examples/dynamic_threads/Cargo.lock index 8b6e754..73a095d 100644 --- a/examples/dynamic_threads/Cargo.lock +++ b/examples/dynamic_threads/Cargo.lock @@ -2,7 +2,7 @@ # It is not intended for manual editing. [[package]] name = "bdwgc-alloc" -version = "0.1.1" +version = "0.2.0" dependencies = [ "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -11,7 +11,7 @@ dependencies = [ name = "dynamic_threads" version = "0.1.0" dependencies = [ - "bdwgc-alloc 0.1.1", + "bdwgc-alloc 0.2.0", ] [[package]] diff --git a/examples/dynamic_threads/src/main.rs b/examples/dynamic_threads/src/main.rs index d436922..6e63a53 100644 --- a/examples/dynamic_threads/src/main.rs +++ b/examples/dynamic_threads/src/main.rs @@ -11,7 +11,7 @@ fn main() { loop { let handle = std::thread::spawn(move || { - Allocator::register_current_thread().unwrap(); + unsafe { Allocator::register_current_thread().unwrap() } let mut _n = unsafe { GLOBAL_ALLOCATOR.alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) }; @@ -20,7 +20,7 @@ fn main() { _n = unsafe { GLOBAL_ALLOCATOR.alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) } } - Allocator::unregister_current_thread(); + unsafe { Allocator::unregister_current_thread() } }); handle.join().unwrap(); diff --git a/examples/static_threads/Cargo.lock b/examples/static_threads/Cargo.lock index 1c2d41c..4e837af 100644 --- a/examples/static_threads/Cargo.lock +++ b/examples/static_threads/Cargo.lock @@ -2,7 +2,7 @@ # It is not intended for manual editing. [[package]] name = "bdwgc-alloc" -version = "0.1.1" +version = "0.2.0" dependencies = [ "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -16,7 +16,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "static_threads" version = "0.1.0" dependencies = [ - "bdwgc-alloc 0.1.1", + "bdwgc-alloc 0.2.0", ] [metadata] diff --git a/examples/static_threads/src/main.rs b/examples/static_threads/src/main.rs index 7ecd79b..da331f2 100644 --- a/examples/static_threads/src/main.rs +++ b/examples/static_threads/src/main.rs @@ -10,7 +10,7 @@ fn main() { unsafe { Allocator::initialize() } let handle = std::thread::spawn(move || { - Allocator::register_current_thread().unwrap(); + unsafe { Allocator::register_current_thread().unwrap() } let mut _n = unsafe { GLOBAL_ALLOCATOR.alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) }; diff --git a/src/lib.rs b/src/lib.rs index baf303b..4105b3d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,23 +32,23 @@ impl Allocator { GC_allow_register_threads(); } - pub fn register_current_thread() -> Result<(), error::Error> { + pub unsafe fn register_current_thread() -> Result<(), error::Error> { let mut base = GcStackBase { mem_base: std::ptr::null(), reg_base: std::ptr::null(), }; - if unsafe { GC_get_stack_base(&mut base) } != GC_SUCCESS { + if GC_get_stack_base(&mut base) != GC_SUCCESS { return Err(error::Error::new("failed to get stack base")); - } else if unsafe { GC_register_my_thread(&base) } != GC_SUCCESS { + } else if GC_register_my_thread(&base) != GC_SUCCESS { return Err(error::Error::new("failed to register a thread for GC")); } Ok(()) } - pub fn unregister_current_thread() { - unsafe { GC_unregister_my_thread() } + pub unsafe fn unregister_current_thread() { + GC_unregister_my_thread() } }