Skip to content

Commit

Permalink
Merge pull request #469 from newAM/issue-464
Browse files Browse the repository at this point in the history
Fix CI
  • Loading branch information
Dirbaio authored May 7, 2024
2 parents 6cd26cc + 6e98625 commit 07c072c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 27 deletions.
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use std::{
};

fn main() -> Result<(), Box<dyn Error>> {
println!("cargo::rustc-check-cfg=cfg(arm_llsc)");
println!("cargo::rustc-check-cfg=cfg(has_atomic_load_store)");

let target = env::var("TARGET")?;

// Manually list targets that have atomic load/store, but no CAS.
Expand Down
26 changes: 17 additions & 9 deletions src/pool/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! // (some `no_std` runtimes have safe APIs to create `&'static mut` references)
//! let block: &'static mut ArcBlock<u128> = unsafe {
//! static mut BLOCK: ArcBlock<u128> = ArcBlock::new();
//! &mut BLOCK
//! addr_of_mut!(BLOCK).as_mut().unwrap()
//! };
//!
//! MyArcPool.manage(block);
Expand Down Expand Up @@ -54,7 +54,7 @@
//! let blocks: &'static mut [ArcBlock<u128>] = {
//! const BLOCK: ArcBlock<u128> = ArcBlock::new(); // <=
//! static mut BLOCKS: [ArcBlock<u128>; POOL_CAPACITY] = [BLOCK; POOL_CAPACITY];
//! unsafe { &mut BLOCKS }
//! unsafe { addr_of_mut!(BLOCK).as_mut().unwrap()S }
//! };
//!
//! for block in blocks {
Expand Down Expand Up @@ -162,6 +162,7 @@ pub struct ArcPoolImpl<T> {
impl<T> ArcPoolImpl<T> {
/// `arc_pool!` implementation detail
#[doc(hidden)]
#[allow(clippy::new_without_default)]
pub const fn new() -> Self {
Self {
stack: Stack::new(),
Expand Down Expand Up @@ -387,9 +388,16 @@ impl<T> ArcBlock<T> {
}
}

impl<T> Default for ArcBlock<T> {
fn default() -> Self {
Self::new()
}
}

#[cfg(test)]
mod tests {
use super::*;
use std::ptr::addr_of_mut;

#[test]
fn cannot_alloc_if_empty() {
Expand All @@ -404,7 +412,7 @@ mod tests {

let block = unsafe {
static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
};
MyArcPool.manage(block);

Expand All @@ -417,7 +425,7 @@ mod tests {

let block = unsafe {
static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
};
MyArcPool.manage(block);

Expand All @@ -434,7 +442,7 @@ mod tests {

let block = unsafe {
static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
};
MyArcPool.manage(block);

Expand All @@ -449,7 +457,7 @@ mod tests {

let block = unsafe {
static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
};
MyArcPool.manage(block);

Expand All @@ -470,7 +478,7 @@ mod tests {

let block = unsafe {
static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
};
MyArcPool.manage(block);

Expand Down Expand Up @@ -501,7 +509,7 @@ mod tests {

let block = unsafe {
static mut BLOCK: ArcBlock<MyStruct> = ArcBlock::new();
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
};
MyArcPool.manage(block);

Expand All @@ -523,7 +531,7 @@ mod tests {

let block = unsafe {
static mut BLOCK: ArcBlock<Zst4096> = ArcBlock::new();
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
};
MyArcPool.manage(block);

Expand Down
32 changes: 20 additions & 12 deletions src/pool/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! // (some `no_std` runtimes have safe APIs to create `&'static mut` references)
//! let block: &'static mut BoxBlock<u128> = unsafe {
//! static mut BLOCK: BoxBlock <u128>= BoxBlock::new();
//! &mut BLOCK
//! addr_of_mut!(BLOCK).as_mut().unwrap()
//! };
//!
//! // give block of memory to the pool
Expand All @@ -33,7 +33,7 @@
//! // give another memory block to the pool
//! MyBoxPool.manage(unsafe {
//! static mut BLOCK: BoxBlock<u128> = BoxBlock::new();
//! &mut BLOCK
//! addr_of_mut!(BLOCK).as_mut().unwrap()
//! });
//!
//! // cloning also consumes a memory block from the pool
Expand Down Expand Up @@ -70,7 +70,7 @@
//! #[allow(clippy::declare_interior_mutable_const)]
//! const BLOCK: BoxBlock<u128> = BoxBlock::new(); // <=
//! static mut BLOCKS: [BoxBlock<u128>; POOL_CAPACITY] = [BLOCK; POOL_CAPACITY];
//! unsafe { &mut BLOCKS }
//! unsafe { addr_of_mut!(BLOCK).as_mut().unwrap()S }
//! };
//!
//! for block in blocks {
Expand Down Expand Up @@ -317,6 +317,7 @@ pub struct BoxPoolImpl<T> {
}

impl<T> BoxPoolImpl<T> {
#[allow(clippy::new_without_default)]
pub const fn new() -> Self {
Self {
stack: Stack::new(),
Expand Down Expand Up @@ -358,9 +359,16 @@ impl<T> BoxBlock<T> {
}
}

impl<T> Default for BoxBlock<T> {
fn default() -> Self {
Self::new()
}
}

#[cfg(test)]
mod tests {
use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::ptr::addr_of_mut;
use std::thread;

use super::*;
Expand All @@ -378,7 +386,7 @@ mod tests {

let block = unsafe {
static mut BLOCK: BoxBlock<i32> = BoxBlock::new();
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
};
MyBoxPool.manage(block);

Expand All @@ -391,7 +399,7 @@ mod tests {

let block = unsafe {
static mut BLOCK: BoxBlock<i32> = BoxBlock::new();
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
};
MyBoxPool.manage(block);

Expand All @@ -418,7 +426,7 @@ mod tests {

let block = unsafe {
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
};
MyBoxPool.manage(block);

Expand All @@ -440,7 +448,7 @@ mod tests {

let block = unsafe {
static mut BLOCK: BoxBlock<Zst4096> = BoxBlock::new();
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
};
MyBoxPool.manage(block);

Expand All @@ -467,11 +475,11 @@ mod tests {

MyBoxPool.manage(unsafe {
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
});
MyBoxPool.manage(unsafe {
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
});

let first = MyBoxPool.alloc(MyStruct).ok().unwrap();
Expand Down Expand Up @@ -500,7 +508,7 @@ mod tests {

MyBoxPool.manage(unsafe {
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
});

let first = MyBoxPool.alloc(MyStruct).ok().unwrap();
Expand Down Expand Up @@ -534,11 +542,11 @@ mod tests {

MyBoxPool.manage(unsafe {
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
});
MyBoxPool.manage(unsafe {
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
});

let boxed = MyBoxPool.alloc(MyStruct).ok().unwrap();
Expand Down
13 changes: 7 additions & 6 deletions src/pool/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//! let block: &'static mut ObjectBlock<[u8; 128]> = unsafe {
//! // unlike the memory pool APIs, an initial value must be specified here
//! static mut BLOCK: ObjectBlock<[u8; 128]>= ObjectBlock::new([0; 128]);
//! &mut BLOCK
//! addr_of_mut!(BLOCK).as_mut().unwrap()
//! };
//!
//! // give object block to the pool
Expand Down Expand Up @@ -55,7 +55,7 @@
//! let blocks: &'static mut [ObjectBlock<[u8; 128]>] = {
//! const BLOCK: ObjectBlock<[u8; 128]> = ObjectBlock::new([0; 128]); // <=
//! static mut BLOCKS: [ObjectBlock<[u8; 128]>; POOL_CAPACITY] = [BLOCK; POOL_CAPACITY];
//! unsafe { &mut BLOCKS }
//! unsafe { addr_of_mut!(BLOCK).as_mut().unwrap()S }
//! };
//!
//! for block in blocks {
Expand Down Expand Up @@ -332,6 +332,7 @@ impl<T> ObjectBlock<T> {
#[cfg(test)]
mod tests {
use core::sync::atomic::{self, AtomicUsize};
use std::ptr::addr_of_mut;

use super::*;

Expand All @@ -348,7 +349,7 @@ mod tests {

let block = unsafe {
static mut BLOCK: ObjectBlock<i32> = ObjectBlock::new(1);
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
};
MyObjectPool.manage(block);

Expand All @@ -361,7 +362,7 @@ mod tests {

let block = unsafe {
static mut BLOCK: ObjectBlock<i32> = ObjectBlock::new(1);
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
};
MyObjectPool.manage(block);

Expand Down Expand Up @@ -389,7 +390,7 @@ mod tests {

let block = unsafe {
static mut BLOCK: ObjectBlock<MyStruct> = ObjectBlock::new(MyStruct);
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
};
MyObjectPool.manage(block);

Expand All @@ -411,7 +412,7 @@ mod tests {

let block = unsafe {
static mut BLOCK: ObjectBlock<Zst4096> = ObjectBlock::new(Zst4096);
&mut BLOCK
addr_of_mut!(BLOCK).as_mut().unwrap()
};
MyObjectPool.manage(block);

Expand Down
2 changes: 2 additions & 0 deletions src/pool/treiber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub trait Node: Sized {
type Data;

fn next(&self) -> &AtomicPtr<Self>;

#[allow(dead_code)] // used conditionally
fn next_mut(&mut self) -> &mut AtomicPtr<Self>;
}

Expand Down

0 comments on commit 07c072c

Please sign in to comment.