Merge pull request #469 from newAM/issue-464

Fix CI
This commit is contained in:
Dario Nieuwenhuis 2024-05-07 13:03:45 +00:00 committed by GitHub
commit 07c072c759
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 49 additions and 27 deletions

View File

@ -9,6 +9,9 @@ use std::{
}; };
fn main() -> Result<(), Box<dyn Error>> { 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")?; let target = env::var("TARGET")?;
// Manually list targets that have atomic load/store, but no CAS. // Manually list targets that have atomic load/store, but no CAS.

View File

@ -13,7 +13,7 @@
//! // (some `no_std` runtimes have safe APIs to create `&'static mut` references) //! // (some `no_std` runtimes have safe APIs to create `&'static mut` references)
//! let block: &'static mut ArcBlock<u128> = unsafe { //! let block: &'static mut ArcBlock<u128> = unsafe {
//! static mut BLOCK: ArcBlock<u128> = ArcBlock::new(); //! static mut BLOCK: ArcBlock<u128> = ArcBlock::new();
//! &mut BLOCK //! addr_of_mut!(BLOCK).as_mut().unwrap()
//! }; //! };
//! //!
//! MyArcPool.manage(block); //! MyArcPool.manage(block);
@ -54,7 +54,7 @@
//! let blocks: &'static mut [ArcBlock<u128>] = { //! let blocks: &'static mut [ArcBlock<u128>] = {
//! const BLOCK: ArcBlock<u128> = ArcBlock::new(); // <= //! const BLOCK: ArcBlock<u128> = ArcBlock::new(); // <=
//! static mut BLOCKS: [ArcBlock<u128>; POOL_CAPACITY] = [BLOCK; POOL_CAPACITY]; //! 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 { //! for block in blocks {
@ -162,6 +162,7 @@ pub struct ArcPoolImpl<T> {
impl<T> ArcPoolImpl<T> { impl<T> ArcPoolImpl<T> {
/// `arc_pool!` implementation detail /// `arc_pool!` implementation detail
#[doc(hidden)] #[doc(hidden)]
#[allow(clippy::new_without_default)]
pub const fn new() -> Self { pub const fn new() -> Self {
Self { Self {
stack: Stack::new(), stack: Stack::new(),
@ -387,9 +388,16 @@ impl<T> ArcBlock<T> {
} }
} }
impl<T> Default for ArcBlock<T> {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use std::ptr::addr_of_mut;
#[test] #[test]
fn cannot_alloc_if_empty() { fn cannot_alloc_if_empty() {
@ -404,7 +412,7 @@ mod tests {
let block = unsafe { let block = unsafe {
static mut BLOCK: ArcBlock<i32> = ArcBlock::new(); static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}; };
MyArcPool.manage(block); MyArcPool.manage(block);
@ -417,7 +425,7 @@ mod tests {
let block = unsafe { let block = unsafe {
static mut BLOCK: ArcBlock<i32> = ArcBlock::new(); static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}; };
MyArcPool.manage(block); MyArcPool.manage(block);
@ -434,7 +442,7 @@ mod tests {
let block = unsafe { let block = unsafe {
static mut BLOCK: ArcBlock<i32> = ArcBlock::new(); static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}; };
MyArcPool.manage(block); MyArcPool.manage(block);
@ -449,7 +457,7 @@ mod tests {
let block = unsafe { let block = unsafe {
static mut BLOCK: ArcBlock<i32> = ArcBlock::new(); static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}; };
MyArcPool.manage(block); MyArcPool.manage(block);
@ -470,7 +478,7 @@ mod tests {
let block = unsafe { let block = unsafe {
static mut BLOCK: ArcBlock<i32> = ArcBlock::new(); static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}; };
MyArcPool.manage(block); MyArcPool.manage(block);
@ -501,7 +509,7 @@ mod tests {
let block = unsafe { let block = unsafe {
static mut BLOCK: ArcBlock<MyStruct> = ArcBlock::new(); static mut BLOCK: ArcBlock<MyStruct> = ArcBlock::new();
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}; };
MyArcPool.manage(block); MyArcPool.manage(block);
@ -523,7 +531,7 @@ mod tests {
let block = unsafe { let block = unsafe {
static mut BLOCK: ArcBlock<Zst4096> = ArcBlock::new(); static mut BLOCK: ArcBlock<Zst4096> = ArcBlock::new();
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}; };
MyArcPool.manage(block); MyArcPool.manage(block);

View File

@ -13,7 +13,7 @@
//! // (some `no_std` runtimes have safe APIs to create `&'static mut` references) //! // (some `no_std` runtimes have safe APIs to create `&'static mut` references)
//! let block: &'static mut BoxBlock<u128> = unsafe { //! let block: &'static mut BoxBlock<u128> = unsafe {
//! static mut BLOCK: BoxBlock <u128>= BoxBlock::new(); //! static mut BLOCK: BoxBlock <u128>= BoxBlock::new();
//! &mut BLOCK //! addr_of_mut!(BLOCK).as_mut().unwrap()
//! }; //! };
//! //!
//! // give block of memory to the pool //! // give block of memory to the pool
@ -33,7 +33,7 @@
//! // give another memory block to the pool //! // give another memory block to the pool
//! MyBoxPool.manage(unsafe { //! MyBoxPool.manage(unsafe {
//! static mut BLOCK: BoxBlock<u128> = BoxBlock::new(); //! 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 //! // cloning also consumes a memory block from the pool
@ -70,7 +70,7 @@
//! #[allow(clippy::declare_interior_mutable_const)] //! #[allow(clippy::declare_interior_mutable_const)]
//! const BLOCK: BoxBlock<u128> = BoxBlock::new(); // <= //! const BLOCK: BoxBlock<u128> = BoxBlock::new(); // <=
//! static mut BLOCKS: [BoxBlock<u128>; POOL_CAPACITY] = [BLOCK; POOL_CAPACITY]; //! 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 { //! for block in blocks {
@ -317,6 +317,7 @@ pub struct BoxPoolImpl<T> {
} }
impl<T> BoxPoolImpl<T> { impl<T> BoxPoolImpl<T> {
#[allow(clippy::new_without_default)]
pub const fn new() -> Self { pub const fn new() -> Self {
Self { Self {
stack: Stack::new(), stack: Stack::new(),
@ -358,9 +359,16 @@ impl<T> BoxBlock<T> {
} }
} }
impl<T> Default for BoxBlock<T> {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::ptr::addr_of_mut;
use std::thread; use std::thread;
use super::*; use super::*;
@ -378,7 +386,7 @@ mod tests {
let block = unsafe { let block = unsafe {
static mut BLOCK: BoxBlock<i32> = BoxBlock::new(); static mut BLOCK: BoxBlock<i32> = BoxBlock::new();
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}; };
MyBoxPool.manage(block); MyBoxPool.manage(block);
@ -391,7 +399,7 @@ mod tests {
let block = unsafe { let block = unsafe {
static mut BLOCK: BoxBlock<i32> = BoxBlock::new(); static mut BLOCK: BoxBlock<i32> = BoxBlock::new();
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}; };
MyBoxPool.manage(block); MyBoxPool.manage(block);
@ -418,7 +426,7 @@ mod tests {
let block = unsafe { let block = unsafe {
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new(); static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}; };
MyBoxPool.manage(block); MyBoxPool.manage(block);
@ -440,7 +448,7 @@ mod tests {
let block = unsafe { let block = unsafe {
static mut BLOCK: BoxBlock<Zst4096> = BoxBlock::new(); static mut BLOCK: BoxBlock<Zst4096> = BoxBlock::new();
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}; };
MyBoxPool.manage(block); MyBoxPool.manage(block);
@ -467,11 +475,11 @@ mod tests {
MyBoxPool.manage(unsafe { MyBoxPool.manage(unsafe {
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new(); static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}); });
MyBoxPool.manage(unsafe { MyBoxPool.manage(unsafe {
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new(); static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}); });
let first = MyBoxPool.alloc(MyStruct).ok().unwrap(); let first = MyBoxPool.alloc(MyStruct).ok().unwrap();
@ -500,7 +508,7 @@ mod tests {
MyBoxPool.manage(unsafe { MyBoxPool.manage(unsafe {
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new(); static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}); });
let first = MyBoxPool.alloc(MyStruct).ok().unwrap(); let first = MyBoxPool.alloc(MyStruct).ok().unwrap();
@ -534,11 +542,11 @@ mod tests {
MyBoxPool.manage(unsafe { MyBoxPool.manage(unsafe {
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new(); static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}); });
MyBoxPool.manage(unsafe { MyBoxPool.manage(unsafe {
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new(); static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}); });
let boxed = MyBoxPool.alloc(MyStruct).ok().unwrap(); let boxed = MyBoxPool.alloc(MyStruct).ok().unwrap();

View File

@ -14,7 +14,7 @@
//! let block: &'static mut ObjectBlock<[u8; 128]> = unsafe { //! let block: &'static mut ObjectBlock<[u8; 128]> = unsafe {
//! // unlike the memory pool APIs, an initial value must be specified here //! // unlike the memory pool APIs, an initial value must be specified here
//! static mut BLOCK: ObjectBlock<[u8; 128]>= ObjectBlock::new([0; 128]); //! 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 //! // give object block to the pool
@ -55,7 +55,7 @@
//! let blocks: &'static mut [ObjectBlock<[u8; 128]>] = { //! let blocks: &'static mut [ObjectBlock<[u8; 128]>] = {
//! const BLOCK: ObjectBlock<[u8; 128]> = ObjectBlock::new([0; 128]); // <= //! const BLOCK: ObjectBlock<[u8; 128]> = ObjectBlock::new([0; 128]); // <=
//! static mut BLOCKS: [ObjectBlock<[u8; 128]>; POOL_CAPACITY] = [BLOCK; POOL_CAPACITY]; //! 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 { //! for block in blocks {
@ -332,6 +332,7 @@ impl<T> ObjectBlock<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use core::sync::atomic::{self, AtomicUsize}; use core::sync::atomic::{self, AtomicUsize};
use std::ptr::addr_of_mut;
use super::*; use super::*;
@ -348,7 +349,7 @@ mod tests {
let block = unsafe { let block = unsafe {
static mut BLOCK: ObjectBlock<i32> = ObjectBlock::new(1); static mut BLOCK: ObjectBlock<i32> = ObjectBlock::new(1);
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}; };
MyObjectPool.manage(block); MyObjectPool.manage(block);
@ -361,7 +362,7 @@ mod tests {
let block = unsafe { let block = unsafe {
static mut BLOCK: ObjectBlock<i32> = ObjectBlock::new(1); static mut BLOCK: ObjectBlock<i32> = ObjectBlock::new(1);
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}; };
MyObjectPool.manage(block); MyObjectPool.manage(block);
@ -389,7 +390,7 @@ mod tests {
let block = unsafe { let block = unsafe {
static mut BLOCK: ObjectBlock<MyStruct> = ObjectBlock::new(MyStruct); static mut BLOCK: ObjectBlock<MyStruct> = ObjectBlock::new(MyStruct);
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}; };
MyObjectPool.manage(block); MyObjectPool.manage(block);
@ -411,7 +412,7 @@ mod tests {
let block = unsafe { let block = unsafe {
static mut BLOCK: ObjectBlock<Zst4096> = ObjectBlock::new(Zst4096); static mut BLOCK: ObjectBlock<Zst4096> = ObjectBlock::new(Zst4096);
&mut BLOCK addr_of_mut!(BLOCK).as_mut().unwrap()
}; };
MyObjectPool.manage(block); MyObjectPool.manage(block);

View File

@ -39,6 +39,8 @@ pub trait Node: Sized {
type Data; type Data;
fn next(&self) -> &AtomicPtr<Self>; fn next(&self) -> &AtomicPtr<Self>;
#[allow(dead_code)] // used conditionally
fn next_mut(&mut self) -> &mut AtomicPtr<Self>; fn next_mut(&mut self) -> &mut AtomicPtr<Self>;
} }