Author SHA1 Message Date
dependabot[bot] 171c882a83 chore(deps): Bump bdwgc-alloc-sys/vendor/libatomic_ops
Bumps [bdwgc-alloc-sys/vendor/libatomic_ops](https://github.com/bdwgc/libatomic_ops) from `d007246` to `c790120`.
- [Release notes](https://github.com/bdwgc/libatomic_ops/releases)
- [Commits](https://github.com/bdwgc/libatomic_ops/compare/d007246aa70fef4f9bfcb84bcc5e6a97653b3d86...c7901207f871e80c973bfeae71f04f7b59c69636)

---
updated-dependencies:
- dependency-name: bdwgc-alloc-sys/vendor/libatomic_ops
  dependency-version: c7901207f871e80c973bfeae71f04f7b59c69636
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-09-28 19:12:15 +00:00
16 changed files with 161 additions and 84 deletions
+8
View File
@@ -21,6 +21,14 @@ jobs:
submodules: true
- uses: swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
- run: cargo test
examples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
submodules: true
- uses: swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
- run: tools/example_test.sh
cmake:
runs-on: ubuntu-latest
steps:
Generated
+28
View File
@@ -106,12 +106,33 @@ dependencies = [
"cc",
]
[[package]]
name = "dynamic_threads"
version = "0.1.0"
dependencies = [
"bdwgc-alloc",
]
[[package]]
name = "find-msvc-tools"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844"
[[package]]
name = "free_by_borrow"
version = "0.1.0"
dependencies = [
"bdwgc-alloc",
]
[[package]]
name = "free_by_gc"
version = "0.1.0"
dependencies = [
"bdwgc-alloc",
]
[[package]]
name = "glob"
version = "0.3.4"
@@ -237,6 +258,13 @@ version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
[[package]]
name = "static_threads"
version = "0.1.0"
dependencies = [
"bdwgc-alloc",
]
[[package]]
name = "syn"
version = "3.0.6"
+2 -1
View File
@@ -1,6 +1,7 @@
[workspace]
resolver = "3"
members = ["bdwgc-alloc", "bdwgc-alloc-sys"]
members = ["bdwgc-alloc", "bdwgc-alloc-sys", "examples/*"]
default-members = ["bdwgc-alloc", "bdwgc-alloc-sys"]
[workspace.package]
version = "0.6.15"
+1 -25
View File
@@ -12,31 +12,7 @@ The raw bindings to the C API of [`bdwgc`][bdwgc] that this crate is built on ar
## Usage
```rust
use bdwgc_alloc::Allocator;
use std::thread::spawn;
#[global_allocator]
static GLOBAL_ALLOCATOR: Allocator = Allocator;
fn main() {
unsafe { Allocator::initialize() }
// Unreachable objects are collected automatically.
Box::leak(Box::new([0u8; 256]));
// Threads other than a main thread must be registered to a collector before allocation.
spawn(|| {
unsafe { Allocator::register_current_thread() }.unwrap();
Box::leak(Box::new([0u8; 256]));
unsafe { Allocator::unregister_current_thread() }
})
.join()
.unwrap();
}
```
See [`examples`](https://github.com/bdwgc/bdwgc-rust/tree/main/examples) directory.
By default [`bdwgc`][bdwgc] is built with autotools. To build with cmake, enable the `cmake` feature:
-4
View File
@@ -18,7 +18,3 @@ cmake = ["bdwgc-alloc-sys/cmake"]
[lints]
workspace = true
[[test]]
name = "allocator"
harness = false
-53
View File
@@ -1,53 +0,0 @@
//! A smoke test of the allocator.
use bdwgc_alloc::Allocator;
use core::hint::black_box;
use std::thread::spawn;
const OBJECT_SIZE: usize = 1 << 8;
const TOTAL_COUNT: usize = 1 << 16;
const THREAD_COUNT: usize = 1 << 6;
#[global_allocator]
static GLOBAL_ALLOCATOR: Allocator = Allocator;
fn main() {
unsafe { Allocator::initialize() }
free_by_gc();
free_by_drop();
static_thread();
dynamic_threads();
}
fn free_by_gc() {
for _ in 0..TOTAL_COUNT {
black_box(Box::leak(Box::new([0u8; OBJECT_SIZE])));
}
}
fn free_by_drop() {
for _ in 0..TOTAL_COUNT {
drop(black_box(Box::new([0u8; OBJECT_SIZE])));
}
}
fn static_thread() {
spawn_thread(free_by_gc);
}
fn dynamic_threads() {
for _ in 0..THREAD_COUNT {
spawn_thread(free_by_gc);
}
}
fn spawn_thread(allocate: fn()) {
spawn(move || {
unsafe { Allocator::register_current_thread() }.unwrap();
allocate();
unsafe { Allocator::unregister_current_thread() }
})
.join()
.unwrap();
}
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "dynamic_threads"
version = "0.1.0"
edition = "2024"
publish = false
[dependencies]
bdwgc-alloc = { path = "../../bdwgc-alloc" }
+23
View File
@@ -0,0 +1,23 @@
use bdwgc_alloc::Allocator;
use std::alloc::Layout;
#[global_allocator]
static GLOBAL_ALLOCATOR: Allocator = Allocator;
fn main() {
unsafe { Allocator::initialize() }
loop {
let handle = std::thread::spawn(move || {
unsafe { Allocator::register_current_thread().unwrap() }
for _ in 0..100 {
let _ = unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
}
unsafe { Allocator::unregister_current_thread() }
});
handle.join().unwrap();
}
}
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "free_by_borrow"
version = "0.1.0"
edition = "2024"
publish = false
[dependencies]
bdwgc-alloc = { path = "../../bdwgc-alloc" }
+14
View File
@@ -0,0 +1,14 @@
use bdwgc_alloc::Allocator;
#[global_allocator]
static GLOBAL_ALLOCATOR: Allocator = Allocator;
fn main() {
unsafe { Allocator::initialize() }
let mut _n: Box<[u8; 2 ^ 8]> = Box::new([0; 2 ^ 8]);
loop {
_n = Box::new([0; 2 ^ 8]);
}
}
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "free_by_gc"
version = "0.1.0"
edition = "2024"
publish = false
[dependencies]
bdwgc-alloc = { path = "../../bdwgc-alloc" }
+13
View File
@@ -0,0 +1,13 @@
use bdwgc_alloc::Allocator;
use std::alloc::Layout;
#[global_allocator]
static GLOBAL_ALLOCATOR: Allocator = Allocator;
fn main() {
unsafe { Allocator::initialize() }
loop {
let _ = unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
}
}
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "static_threads"
version = "0.1.0"
edition = "2024"
publish = false
[dependencies]
bdwgc-alloc = { path = "../../bdwgc-alloc" }
+19
View File
@@ -0,0 +1,19 @@
use bdwgc_alloc::Allocator;
use std::alloc::Layout;
#[global_allocator]
static GLOBAL_ALLOCATOR: Allocator = Allocator;
fn main() {
unsafe { Allocator::initialize() }
let handle = std::thread::spawn(move || {
unsafe { Allocator::register_current_thread().unwrap() }
loop {
let _ = unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
}
});
handle.join().unwrap();
}
+20
View File
@@ -0,0 +1,20 @@
#!/bin/sh
set -ex
duration=20
cd $(dirname $0)/..
for directory in $(ls examples); do
(
cd examples/$directory
cargo build
cargo run &
pid=$!
sleep $duration
kill $pid
)
done