forked from GitHub/bdwgc-rust
Compare commits
25 Commits
v0.6.6
...
chore/poin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e11647fab9 | ||
|
|
21b6fb35ff | ||
|
|
10e16366d7 | ||
|
|
9dd6bfd031 | ||
|
|
f20c12e508 | ||
|
|
e59c09749a | ||
|
|
1e54b65b9e | ||
|
|
7f2429fe25 | ||
|
|
08d549315b | ||
|
|
a4bcbf2c7b | ||
|
|
5f41a2b8e2 | ||
|
|
3a1ddbb6ea | ||
|
|
4412c9d243 | ||
|
|
4485210edd | ||
|
|
542c989250 | ||
|
|
61a78a5c05 | ||
|
|
c7c1a78196 | ||
|
|
4cd0e9de5f | ||
|
|
ca5bb30856 | ||
|
|
12ee9cf0ac | ||
|
|
8f50af7f15 | ||
|
|
e927fa0f23 | ||
|
|
a1902ccc8b | ||
|
|
7f5dec371a | ||
|
|
472b815393 |
@@ -1,11 +1,18 @@
|
|||||||
{
|
{
|
||||||
"words": [
|
"words": [
|
||||||
|
"autogen",
|
||||||
|
"autotools",
|
||||||
|
"bdwgc",
|
||||||
|
"cflag",
|
||||||
"dealloc",
|
"dealloc",
|
||||||
"finalizer",
|
"finalizer",
|
||||||
"gcollect",
|
"gcollect",
|
||||||
|
"libatomic",
|
||||||
"libc",
|
"libc",
|
||||||
"realloc",
|
"realloc",
|
||||||
"repr",
|
"repr",
|
||||||
"stackbottom"
|
"rustc",
|
||||||
|
"stackbottom",
|
||||||
|
"unregisters"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
8
.github/workflows/lint.yaml
vendored
8
.github/workflows/lint.yaml
vendored
@@ -8,7 +8,7 @@ jobs:
|
|||||||
lint:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
@@ -16,19 +16,19 @@ jobs:
|
|||||||
format:
|
format:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- run: cargo fmt -- --check
|
- run: cargo fmt -- --check
|
||||||
spell-check:
|
spell-check:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- uses: streetsidesoftware/cspell-action@main
|
- uses: streetsidesoftware/cspell-action@main
|
||||||
with:
|
with:
|
||||||
files: "**/*.{md,rs}"
|
files: "**/*.{md,rs}"
|
||||||
readme:
|
readme:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- uses: lycheeverse/lychee-action@v1
|
- uses: lycheeverse/lychee-action@v1
|
||||||
with:
|
with:
|
||||||
fail: true
|
fail: true
|
||||||
|
|||||||
12
.github/workflows/test.yaml
vendored
12
.github/workflows/test.yaml
vendored
@@ -8,7 +8,7 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
@@ -16,7 +16,7 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
@@ -24,17 +24,15 @@ jobs:
|
|||||||
examples:
|
examples:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: examples/test.sh
|
||||||
cd examples
|
|
||||||
./test.sh
|
|
||||||
cmake:
|
cmake:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bdwgc-alloc"
|
name = "bdwgc-alloc"
|
||||||
description = "impl GlobalAlloc for bdwgc"
|
description = "impl GlobalAlloc for bdwgc"
|
||||||
version = "0.6.6"
|
version = "0.6.7"
|
||||||
authors = [
|
authors = [
|
||||||
"swgillespie <sean.william.g@gmail.com>",
|
"swgillespie <sean.william.g@gmail.com>",
|
||||||
"Yota Toyama <raviqqe@gmail.com>",
|
"Yota Toyama <raviqqe@gmail.com>",
|
||||||
@@ -9,7 +9,6 @@ authors = [
|
|||||||
repository = "https://github.com/raviqqe/bdwgc-alloc"
|
repository = "https://github.com/raviqqe/bdwgc-alloc"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
build = "build.rs"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["autotools"]
|
default = ["autotools"]
|
||||||
|
|||||||
7
build.rs
7
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",
|
"-I{} -L/lib/x86_64-linux-gnu -lpthread -fPIC -D POINTER_MASK=0x7",
|
||||||
dst.join("include").display()
|
dst.join("include").display()
|
||||||
))
|
))
|
||||||
.build();
|
.build();
|
||||||
@@ -59,7 +59,10 @@ fn main() {
|
|||||||
let dst = Config::new(LIB_GC_DIR)
|
let dst = Config::new(LIB_GC_DIR)
|
||||||
.profile("Release")
|
.profile("Release")
|
||||||
.define("BUILD_SHARED_LIBS", "FALSE")
|
.define("BUILD_SHARED_LIBS", "FALSE")
|
||||||
.cflag(format!("-I{}", libatomic_include_path))
|
.cflag(format!(
|
||||||
|
"-I{} -DPOINTER_MASK=0x7",
|
||||||
|
libatomic_include_path, foo
|
||||||
|
))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
|
resolver = "2"
|
||||||
members = [
|
members = [
|
||||||
"dynamic_threads",
|
"dynamic_threads",
|
||||||
"free_by_borrow",
|
"free_by_borrow",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
name = "dynamic_threads"
|
name = "dynamic_threads"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
extern crate bdwgc_alloc;
|
|
||||||
|
|
||||||
use bdwgc_alloc::Allocator;
|
use bdwgc_alloc::Allocator;
|
||||||
use std::alloc::Layout;
|
use std::alloc::Layout;
|
||||||
|
|
||||||
@@ -14,7 +12,7 @@ fn main() {
|
|||||||
unsafe { Allocator::register_current_thread().unwrap() }
|
unsafe { Allocator::register_current_thread().unwrap() }
|
||||||
|
|
||||||
for _ in 0..100 {
|
for _ in 0..100 {
|
||||||
unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
|
let _ = unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe { Allocator::unregister_current_thread() }
|
unsafe { Allocator::unregister_current_thread() }
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
name = "free_by_borrow"
|
name = "free_by_borrow"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
extern crate bdwgc_alloc;
|
|
||||||
|
|
||||||
use bdwgc_alloc::Allocator;
|
use bdwgc_alloc::Allocator;
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
name = "free_by_gc"
|
name = "free_by_gc"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
extern crate bdwgc_alloc;
|
|
||||||
|
|
||||||
use bdwgc_alloc::Allocator;
|
use bdwgc_alloc::Allocator;
|
||||||
use std::alloc::Layout;
|
use std::alloc::Layout;
|
||||||
|
|
||||||
@@ -10,6 +8,6 @@ fn main() {
|
|||||||
unsafe { Allocator::initialize() }
|
unsafe { Allocator::initialize() }
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
|
let _ = unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
name = "static_threads"
|
name = "static_threads"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
extern crate bdwgc_alloc;
|
|
||||||
|
|
||||||
use bdwgc_alloc::Allocator;
|
use bdwgc_alloc::Allocator;
|
||||||
use std::alloc::Layout;
|
use std::alloc::Layout;
|
||||||
|
|
||||||
@@ -13,7 +11,7 @@ fn main() {
|
|||||||
unsafe { Allocator::register_current_thread().unwrap() }
|
unsafe { Allocator::register_current_thread().unwrap() }
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
|
let _ = unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
cargo build
|
cd $(dirname $0)
|
||||||
|
|
||||||
for cargo_file in */Cargo.toml
|
for cargo_file in */Cargo.toml; do
|
||||||
do
|
cargo run --bin $(dirname $cargo_file) &
|
||||||
target/debug/$(dirname $cargo_file) &
|
pid=$!
|
||||||
pid=$!
|
sleep 20
|
||||||
sleep 10
|
kill $pid
|
||||||
kill $pid
|
|
||||||
done
|
done
|
||||||
|
|||||||
34
src/lib.rs
34
src/lib.rs
@@ -25,6 +25,7 @@ extern "C" {
|
|||||||
fn GC_get_stack_base(stack_base: *mut GcStackBase) -> c_int;
|
fn GC_get_stack_base(stack_base: *mut GcStackBase) -> c_int;
|
||||||
fn GC_init();
|
fn GC_init();
|
||||||
fn GC_malloc(size: size_t) -> *mut c_void;
|
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_realloc(ptr: *mut c_void, size: size_t) -> *mut c_void;
|
||||||
fn GC_register_my_thread(stack_base: *const GcStackBase) -> c_int;
|
fn GC_register_my_thread(stack_base: *const GcStackBase) -> c_int;
|
||||||
fn GC_set_stackbottom(thread: *const c_void, stack_bottom: *const GcStackBase);
|
fn GC_set_stackbottom(thread: *const c_void, stack_bottom: *const GcStackBase);
|
||||||
@@ -42,19 +43,31 @@ extern "C" {
|
|||||||
pub struct Allocator;
|
pub struct Allocator;
|
||||||
|
|
||||||
impl Allocator {
|
impl Allocator {
|
||||||
|
/// Locks a collector.
|
||||||
pub fn lock() {
|
pub fn lock() {
|
||||||
unsafe { GC_alloc_lock() }
|
unsafe { GC_alloc_lock() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Unlocks a collector.
|
||||||
pub fn unlock() {
|
pub fn unlock() {
|
||||||
unsafe { GC_alloc_unlock() }
|
unsafe { GC_alloc_unlock() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Initializes a collector.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// This function must be called in a main thread.
|
||||||
pub unsafe fn initialize() {
|
pub unsafe fn initialize() {
|
||||||
GC_init();
|
GC_init();
|
||||||
GC_allow_register_threads();
|
GC_allow_register_threads();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Registers a current thread to a collector.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// This function must not be called in a main thread.
|
||||||
pub unsafe fn register_current_thread() -> Result<(), error::Error> {
|
pub unsafe fn register_current_thread() -> Result<(), error::Error> {
|
||||||
let mut base = GcStackBase { mem_base: null() };
|
let mut base = GcStackBase { mem_base: null() };
|
||||||
|
|
||||||
@@ -67,6 +80,14 @@ impl Allocator {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets a bottom of a stack.
|
||||||
|
///
|
||||||
|
/// You do not have to call this function in most cases.
|
||||||
|
/// A collector detects the bottom on initialization automatically.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The bottom address must be valid.
|
||||||
pub unsafe fn set_stack_bottom(bottom: *const u8) {
|
pub unsafe fn set_stack_bottom(bottom: *const u8) {
|
||||||
GC_set_stackbottom(
|
GC_set_stackbottom(
|
||||||
null(),
|
null(),
|
||||||
@@ -76,14 +97,25 @@ impl Allocator {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Unregisters a current thread from a collector.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The thread must be registered already.
|
||||||
pub unsafe fn unregister_current_thread() {
|
pub unsafe fn unregister_current_thread() {
|
||||||
GC_unregister_my_thread()
|
GC_unregister_my_thread()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Runs a garbage collection forcibly.
|
||||||
pub fn force_collect() {
|
pub fn force_collect() {
|
||||||
unsafe { GC_gcollect() }
|
unsafe { GC_gcollect() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Registers a finalizer of an object.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The given finalizer must not be null and handle pointers properly.
|
||||||
pub unsafe fn register_finalizer(
|
pub unsafe fn register_finalizer(
|
||||||
ptr: *const c_void,
|
ptr: *const c_void,
|
||||||
finalizer: extern "C" fn(*mut c_void, *mut c_void),
|
finalizer: extern "C" fn(*mut c_void, *mut c_void),
|
||||||
@@ -95,7 +127,7 @@ impl Allocator {
|
|||||||
|
|
||||||
unsafe impl GlobalAlloc for Allocator {
|
unsafe impl GlobalAlloc for Allocator {
|
||||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||||
GC_malloc(layout.size()) as *mut u8
|
GC_memalign(layout.align(), layout.size()) as *mut u8
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
|
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
|
||||||
|
|||||||
2
vendor/bdwgc
vendored
2
vendor/bdwgc
vendored
Submodule vendor/bdwgc updated: 97f27a46f9...e8c073d786
2
vendor/libatomic_ops
vendored
2
vendor/libatomic_ops
vendored
Submodule vendor/libatomic_ops updated: fa4df52730...9f6bc3b928
Reference in New Issue
Block a user