mirror of
https://github.com/bdwgc/bdwgc-rust.git
synced 2026-05-29 18:08:56 -06:00
Fix
This commit is contained in:
2
build.rs
2
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();
|
||||
|
||||
@@ -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() }
|
||||
|
||||
loop {
|
||||
let ptr = allocate();
|
||||
unsafe { *ptr = 0 };
|
||||
}
|
||||
});
|
||||
|
||||
let t2 = spawn(|| {
|
||||
unsafe { Allocator::register_current_thread().unwrap() }
|
||||
|
||||
let x = allocate();
|
||||
|
||||
unsafe { *x = 42 };
|
||||
|
||||
loop {
|
||||
assert_eq!(unsafe { *((x as usize & !BITS) as *mut usize) }, 42);
|
||||
}
|
||||
});
|
||||
let x = x as usize | BITS;
|
||||
let mut xs = vec![];
|
||||
|
||||
t1.join().unwrap();
|
||||
t2.join().unwrap();
|
||||
loop {
|
||||
assert_eq!(x & BITS, BITS);
|
||||
assert_eq!(unsafe { *((x & !BITS) as *mut usize) }, 42);
|
||||
|
||||
let ptr = allocate();
|
||||
unsafe { *ptr = 0 };
|
||||
xs.push(ptr);
|
||||
|
||||
Allocator::force_collect();
|
||||
}
|
||||
}
|
||||
|
||||
fn allocate() -> *mut usize {
|
||||
(unsafe { alloc(Layout::new::<usize>()) }) as *mut usize
|
||||
(unsafe { alloc(Layout::from_size_align(1 << 8, 8).unwrap()) }) as *mut usize
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user