diff --git a/build.rs b/build.rs index bb89741..2cbf54e 100644 --- a/build.rs +++ b/build.rs @@ -23,7 +23,7 @@ fn main() { let dst = autotools::Config::new(LIB_GC_DIR) .cflag(format!( - "-I{} -L/lib/x86_64-linux-gnu -lpthread -fPIC -DPOINTER_MASK=0xfffffffffffffff8", + "-I{} -L/lib/x86_64-linux-gnu -lpthread -fPIC", dst.join("include").display() )) .build(); diff --git a/examples/tagged_pointer/src/main.rs b/examples/tagged_pointer/src/main.rs index 9bda75f..64a421d 100644 --- a/examples/tagged_pointer/src/main.rs +++ b/examples/tagged_pointer/src/main.rs @@ -1,10 +1,7 @@ use bdwgc_alloc::Allocator; -use std::{ - alloc::{alloc, Layout}, - thread::spawn, -}; +use std::alloc::{alloc, Layout}; -const BITS: usize = 7 << 48; +const BITS: usize = (1 << 8 - 1) << 48; #[global_allocator] static GLOBAL_ALLOCATOR: Allocator = Allocator; @@ -12,31 +9,25 @@ static GLOBAL_ALLOCATOR: Allocator = Allocator; fn main() { unsafe { Allocator::initialize() } - let t1 = spawn(|| { - unsafe { Allocator::register_current_thread().unwrap() } + let x = allocate(); - loop { - let ptr = allocate(); - unsafe { *ptr = 0 }; - } - }); + unsafe { *x = 42 }; - let t2 = spawn(|| { - unsafe { Allocator::register_current_thread().unwrap() } + let x = x as usize | BITS; + let mut xs = vec![]; - let x = allocate(); + loop { + assert_eq!(x & BITS, BITS); + assert_eq!(unsafe { *((x & !BITS) as *mut usize) }, 42); - unsafe { *x = 42 }; + let ptr = allocate(); + unsafe { *ptr = 0 }; + xs.push(ptr); - loop { - assert_eq!(unsafe { *((x as usize & !BITS) as *mut usize) }, 42); - } - }); - - t1.join().unwrap(); - t2.join().unwrap(); + Allocator::force_collect(); + } } fn allocate() -> *mut usize { - (unsafe { alloc(Layout::new::()) }) as *mut usize + (unsafe { alloc(Layout::from_size_align(1 << 8, 8).unwrap()) }) as *mut usize }