mirror of
https://github.com/bdwgc/bdwgc-rust.git
synced 2026-05-30 10:28:56 -06:00
Compare commits
13 Commits
chore/poin
...
feature/ta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56de2259dd | ||
|
|
e6e76b629b | ||
|
|
b540c0597c | ||
|
|
10ffdd9351 | ||
|
|
0bd260a7c0 | ||
|
|
6cb47fddd0 | ||
|
|
039a10213d | ||
|
|
b204c1a6a2 | ||
|
|
44fff26f2f | ||
|
|
ef9675ab17 | ||
|
|
4bf1effc4b | ||
|
|
1aaf2fb621 | ||
|
|
25631ef919 |
@@ -3,6 +3,7 @@
|
||||
"autogen",
|
||||
"autotools",
|
||||
"bdwgc",
|
||||
"canonicalize",
|
||||
"cflag",
|
||||
"dealloc",
|
||||
"finalizer",
|
||||
|
||||
8
build.rs
8
build.rs
@@ -23,7 +23,8 @@ fn main() {
|
||||
|
||||
let dst = autotools::Config::new(LIB_GC_DIR)
|
||||
.cflag(format!(
|
||||
"-I{} -L/lib/x86_64-linux-gnu -lpthread -fPIC -D POINTER_MASK=0x7",
|
||||
// spell-checker: disable-next-line
|
||||
"-I{} -L/lib/x86_64-linux-gnu -lpthread -fPIC",
|
||||
dst.join("include").display()
|
||||
))
|
||||
.build();
|
||||
@@ -59,10 +60,7 @@ fn main() {
|
||||
let dst = Config::new(LIB_GC_DIR)
|
||||
.profile("Release")
|
||||
.define("BUILD_SHARED_LIBS", "FALSE")
|
||||
.cflag(format!(
|
||||
"-I{} -DPOINTER_MASK=0x7",
|
||||
libatomic_include_path, foo
|
||||
))
|
||||
.cflag(format!("-I{}", libatomic_include_path))
|
||||
.build();
|
||||
|
||||
println!(
|
||||
|
||||
@@ -5,4 +5,5 @@ members = [
|
||||
"free_by_borrow",
|
||||
"free_by_gc",
|
||||
"static_threads",
|
||||
"tagged_pointer",
|
||||
]
|
||||
|
||||
9
examples/tagged_pointer/Cargo.toml
Normal file
9
examples/tagged_pointer/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "tagged_pointer"
|
||||
version = "0.1.0"
|
||||
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
bdwgc-alloc = { path = "../.." }
|
||||
27
examples/tagged_pointer/src/main.rs
Normal file
27
examples/tagged_pointer/src/main.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use bdwgc_alloc::Allocator;
|
||||
use std::alloc::{alloc, Layout};
|
||||
|
||||
const BITS: usize = usize::MAX << 48 | 0x7;
|
||||
|
||||
#[global_allocator]
|
||||
static GLOBAL_ALLOCATOR: Allocator = Allocator;
|
||||
|
||||
fn main() {
|
||||
unsafe { Allocator::initialize() }
|
||||
|
||||
loop {
|
||||
let x = allocate();
|
||||
unsafe { *x = 42 };
|
||||
let x = x as usize | BITS;
|
||||
|
||||
assert_eq!(x & BITS, BITS);
|
||||
|
||||
Allocator::force_collect();
|
||||
|
||||
assert_eq!(unsafe { *((x & !BITS) as *mut usize) }, 42);
|
||||
}
|
||||
}
|
||||
|
||||
fn allocate() -> *mut usize {
|
||||
(unsafe { alloc(Layout::from_size_align(1 << 8, 8).unwrap()) }) as *mut usize
|
||||
}
|
||||
@@ -25,7 +25,6 @@ extern "C" {
|
||||
fn GC_get_stack_base(stack_base: *mut GcStackBase) -> c_int;
|
||||
fn GC_init();
|
||||
fn GC_malloc(size: size_t) -> *mut c_void;
|
||||
fn GC_memalign(align: size_t, size: size_t) -> *mut c_void;
|
||||
fn GC_realloc(ptr: *mut c_void, size: size_t) -> *mut c_void;
|
||||
fn GC_register_my_thread(stack_base: *const GcStackBase) -> c_int;
|
||||
fn GC_set_stackbottom(thread: *const c_void, stack_bottom: *const GcStackBase);
|
||||
@@ -127,7 +126,7 @@ impl Allocator {
|
||||
|
||||
unsafe impl GlobalAlloc for Allocator {
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||
GC_memalign(layout.align(), layout.size()) as *mut u8
|
||||
GC_malloc(layout.size()) as *mut u8
|
||||
}
|
||||
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
|
||||
|
||||
Reference in New Issue
Block a user