mirror of
https://github.com/bdwgc/bdwgc-rust.git
synced 2026-05-29 18:08:56 -06:00
Merge branch 'main' into chore/pointer-mask
This commit is contained in:
@@ -1,11 +1,18 @@
|
||||
{
|
||||
"words": [
|
||||
"autogen",
|
||||
"autotools",
|
||||
"bdwgc",
|
||||
"cflag",
|
||||
"dealloc",
|
||||
"finalizer",
|
||||
"gcollect",
|
||||
"libatomic",
|
||||
"libc",
|
||||
"realloc",
|
||||
"repr",
|
||||
"stackbottom"
|
||||
"rustc",
|
||||
"stackbottom",
|
||||
"unregisters"
|
||||
]
|
||||
}
|
||||
|
||||
4
.github/workflows/test.yaml
vendored
4
.github/workflows/test.yaml
vendored
@@ -28,9 +28,7 @@ jobs:
|
||||
with:
|
||||
submodules: true
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: |
|
||||
cd examples
|
||||
./test.sh
|
||||
- run: examples/test.sh
|
||||
cmake:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "bdwgc-alloc"
|
||||
description = "impl GlobalAlloc for bdwgc"
|
||||
version = "0.6.6"
|
||||
version = "0.6.7"
|
||||
authors = [
|
||||
"swgillespie <sean.william.g@gmail.com>",
|
||||
"Yota Toyama <raviqqe@gmail.com>",
|
||||
@@ -9,7 +9,6 @@ authors = [
|
||||
repository = "https://github.com/raviqqe/bdwgc-alloc"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
build = "build.rs"
|
||||
|
||||
[features]
|
||||
default = ["autotools"]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
members = [
|
||||
"dynamic_threads",
|
||||
"free_by_borrow",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "dynamic_threads"
|
||||
version = "0.1.0"
|
||||
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
extern crate bdwgc_alloc;
|
||||
|
||||
use bdwgc_alloc::Allocator;
|
||||
use std::alloc::Layout;
|
||||
|
||||
@@ -14,7 +12,7 @@ fn main() {
|
||||
unsafe { Allocator::register_current_thread().unwrap() }
|
||||
|
||||
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() }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "free_by_borrow"
|
||||
version = "0.1.0"
|
||||
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
extern crate bdwgc_alloc;
|
||||
|
||||
use bdwgc_alloc::Allocator;
|
||||
|
||||
#[global_allocator]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "free_by_gc"
|
||||
version = "0.1.0"
|
||||
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
extern crate bdwgc_alloc;
|
||||
|
||||
use bdwgc_alloc::Allocator;
|
||||
use std::alloc::Layout;
|
||||
|
||||
@@ -10,6 +8,6 @@ fn main() {
|
||||
unsafe { Allocator::initialize() }
|
||||
|
||||
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"
|
||||
version = "0.1.0"
|
||||
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
extern crate bdwgc_alloc;
|
||||
|
||||
use bdwgc_alloc::Allocator;
|
||||
use std::alloc::Layout;
|
||||
|
||||
@@ -13,7 +11,7 @@ fn main() {
|
||||
unsafe { Allocator::register_current_thread().unwrap() }
|
||||
|
||||
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
|
||||
|
||||
cargo build
|
||||
cd $(dirname $0)
|
||||
|
||||
for cargo_file in */Cargo.toml
|
||||
do
|
||||
target/debug/$(dirname $cargo_file) &
|
||||
pid=$!
|
||||
sleep 10
|
||||
kill $pid
|
||||
for cargo_file in */Cargo.toml; do
|
||||
cargo run --bin $(dirname $cargo_file) &
|
||||
pid=$!
|
||||
sleep 20
|
||||
kill $pid
|
||||
done
|
||||
|
||||
31
src/lib.rs
31
src/lib.rs
@@ -43,19 +43,31 @@ extern "C" {
|
||||
pub struct Allocator;
|
||||
|
||||
impl Allocator {
|
||||
/// Locks a collector.
|
||||
pub fn lock() {
|
||||
unsafe { GC_alloc_lock() }
|
||||
}
|
||||
|
||||
/// Unlocks a collector.
|
||||
pub fn unlock() {
|
||||
unsafe { GC_alloc_unlock() }
|
||||
}
|
||||
|
||||
/// Initializes a collector.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This function must be called in a main thread.
|
||||
pub unsafe fn initialize() {
|
||||
GC_init();
|
||||
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> {
|
||||
let mut base = GcStackBase { mem_base: null() };
|
||||
|
||||
@@ -68,6 +80,14 @@ impl Allocator {
|
||||
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) {
|
||||
GC_set_stackbottom(
|
||||
null(),
|
||||
@@ -77,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() {
|
||||
GC_unregister_my_thread()
|
||||
}
|
||||
|
||||
/// Runs a garbage collection forcibly.
|
||||
pub fn force_collect() {
|
||||
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(
|
||||
ptr: *const c_void,
|
||||
finalizer: extern "C" fn(*mut c_void, *mut c_void),
|
||||
|
||||
2
vendor/bdwgc
vendored
2
vendor/bdwgc
vendored
Submodule vendor/bdwgc updated: 4ae9dcd894...e8c073d786
Reference in New Issue
Block a user