mirror of
https://github.com/bdwgc/bdwgc-rust.git
synced 2026-05-30 02:18:57 -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)
|
let dst = autotools::Config::new(LIB_GC_DIR)
|
||||||
.cflag(format!(
|
.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()
|
dst.join("include").display()
|
||||||
))
|
))
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
use bdwgc_alloc::Allocator;
|
use bdwgc_alloc::Allocator;
|
||||||
use std::{
|
use std::alloc::{alloc, Layout};
|
||||||
alloc::{alloc, Layout},
|
|
||||||
thread::spawn,
|
|
||||||
};
|
|
||||||
|
|
||||||
const BITS: usize = 7 << 48;
|
const BITS: usize = (1 << 8 - 1) << 48;
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static GLOBAL_ALLOCATOR: Allocator = Allocator;
|
static GLOBAL_ALLOCATOR: Allocator = Allocator;
|
||||||
@@ -12,31 +9,25 @@ static GLOBAL_ALLOCATOR: Allocator = Allocator;
|
|||||||
fn main() {
|
fn main() {
|
||||||
unsafe { Allocator::initialize() }
|
unsafe { Allocator::initialize() }
|
||||||
|
|
||||||
let t1 = spawn(|| {
|
let x = allocate();
|
||||||
unsafe { Allocator::register_current_thread().unwrap() }
|
|
||||||
|
|
||||||
loop {
|
unsafe { *x = 42 };
|
||||||
let ptr = allocate();
|
|
||||||
unsafe { *ptr = 0 };
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let t2 = spawn(|| {
|
let x = x as usize | BITS;
|
||||||
unsafe { Allocator::register_current_thread().unwrap() }
|
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 {
|
Allocator::force_collect();
|
||||||
assert_eq!(unsafe { *((x as usize & !BITS) as *mut usize) }, 42);
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
t1.join().unwrap();
|
|
||||||
t2.join().unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn allocate() -> *mut usize {
|
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