Skip to content

Commit 07c072c

Browse files
authored
Merge pull request #469 from newAM/issue-464
Fix CI
2 parents 6cd26cc + 6e98625 commit 07c072c

File tree

5 files changed

+49
-27
lines changed

5 files changed

+49
-27
lines changed

build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use std::{
99
};
1010

1111
fn main() -> Result<(), Box<dyn Error>> {
12+
println!("cargo::rustc-check-cfg=cfg(arm_llsc)");
13+
println!("cargo::rustc-check-cfg=cfg(has_atomic_load_store)");
14+
1215
let target = env::var("TARGET")?;
1316

1417
// Manually list targets that have atomic load/store, but no CAS.

src/pool/arc.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! // (some `no_std` runtimes have safe APIs to create `&'static mut` references)
1414
//! let block: &'static mut ArcBlock<u128> = unsafe {
1515
//! static mut BLOCK: ArcBlock<u128> = ArcBlock::new();
16-
//! &mut BLOCK
16+
//! addr_of_mut!(BLOCK).as_mut().unwrap()
1717
//! };
1818
//!
1919
//! MyArcPool.manage(block);
@@ -54,7 +54,7 @@
5454
//! let blocks: &'static mut [ArcBlock<u128>] = {
5555
//! const BLOCK: ArcBlock<u128> = ArcBlock::new(); // <=
5656
//! static mut BLOCKS: [ArcBlock<u128>; POOL_CAPACITY] = [BLOCK; POOL_CAPACITY];
57-
//! unsafe { &mut BLOCKS }
57+
//! unsafe { addr_of_mut!(BLOCK).as_mut().unwrap()S }
5858
//! };
5959
//!
6060
//! for block in blocks {
@@ -162,6 +162,7 @@ pub struct ArcPoolImpl<T> {
162162
impl<T> ArcPoolImpl<T> {
163163
/// `arc_pool!` implementation detail
164164
#[doc(hidden)]
165+
#[allow(clippy::new_without_default)]
165166
pub const fn new() -> Self {
166167
Self {
167168
stack: Stack::new(),
@@ -387,9 +388,16 @@ impl<T> ArcBlock<T> {
387388
}
388389
}
389390

391+
impl<T> Default for ArcBlock<T> {
392+
fn default() -> Self {
393+
Self::new()
394+
}
395+
}
396+
390397
#[cfg(test)]
391398
mod tests {
392399
use super::*;
400+
use std::ptr::addr_of_mut;
393401

394402
#[test]
395403
fn cannot_alloc_if_empty() {
@@ -404,7 +412,7 @@ mod tests {
404412

405413
let block = unsafe {
406414
static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
407-
&mut BLOCK
415+
addr_of_mut!(BLOCK).as_mut().unwrap()
408416
};
409417
MyArcPool.manage(block);
410418

@@ -417,7 +425,7 @@ mod tests {
417425

418426
let block = unsafe {
419427
static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
420-
&mut BLOCK
428+
addr_of_mut!(BLOCK).as_mut().unwrap()
421429
};
422430
MyArcPool.manage(block);
423431

@@ -434,7 +442,7 @@ mod tests {
434442

435443
let block = unsafe {
436444
static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
437-
&mut BLOCK
445+
addr_of_mut!(BLOCK).as_mut().unwrap()
438446
};
439447
MyArcPool.manage(block);
440448

@@ -449,7 +457,7 @@ mod tests {
449457

450458
let block = unsafe {
451459
static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
452-
&mut BLOCK
460+
addr_of_mut!(BLOCK).as_mut().unwrap()
453461
};
454462
MyArcPool.manage(block);
455463

@@ -470,7 +478,7 @@ mod tests {
470478

471479
let block = unsafe {
472480
static mut BLOCK: ArcBlock<i32> = ArcBlock::new();
473-
&mut BLOCK
481+
addr_of_mut!(BLOCK).as_mut().unwrap()
474482
};
475483
MyArcPool.manage(block);
476484

@@ -501,7 +509,7 @@ mod tests {
501509

502510
let block = unsafe {
503511
static mut BLOCK: ArcBlock<MyStruct> = ArcBlock::new();
504-
&mut BLOCK
512+
addr_of_mut!(BLOCK).as_mut().unwrap()
505513
};
506514
MyArcPool.manage(block);
507515

@@ -523,7 +531,7 @@ mod tests {
523531

524532
let block = unsafe {
525533
static mut BLOCK: ArcBlock<Zst4096> = ArcBlock::new();
526-
&mut BLOCK
534+
addr_of_mut!(BLOCK).as_mut().unwrap()
527535
};
528536
MyArcPool.manage(block);
529537

src/pool/boxed.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! // (some `no_std` runtimes have safe APIs to create `&'static mut` references)
1414
//! let block: &'static mut BoxBlock<u128> = unsafe {
1515
//! static mut BLOCK: BoxBlock <u128>= BoxBlock::new();
16-
//! &mut BLOCK
16+
//! addr_of_mut!(BLOCK).as_mut().unwrap()
1717
//! };
1818
//!
1919
//! // give block of memory to the pool
@@ -33,7 +33,7 @@
3333
//! // give another memory block to the pool
3434
//! MyBoxPool.manage(unsafe {
3535
//! static mut BLOCK: BoxBlock<u128> = BoxBlock::new();
36-
//! &mut BLOCK
36+
//! addr_of_mut!(BLOCK).as_mut().unwrap()
3737
//! });
3838
//!
3939
//! // cloning also consumes a memory block from the pool
@@ -70,7 +70,7 @@
7070
//! #[allow(clippy::declare_interior_mutable_const)]
7171
//! const BLOCK: BoxBlock<u128> = BoxBlock::new(); // <=
7272
//! static mut BLOCKS: [BoxBlock<u128>; POOL_CAPACITY] = [BLOCK; POOL_CAPACITY];
73-
//! unsafe { &mut BLOCKS }
73+
//! unsafe { addr_of_mut!(BLOCK).as_mut().unwrap()S }
7474
//! };
7575
//!
7676
//! for block in blocks {
@@ -317,6 +317,7 @@ pub struct BoxPoolImpl<T> {
317317
}
318318

319319
impl<T> BoxPoolImpl<T> {
320+
#[allow(clippy::new_without_default)]
320321
pub const fn new() -> Self {
321322
Self {
322323
stack: Stack::new(),
@@ -358,9 +359,16 @@ impl<T> BoxBlock<T> {
358359
}
359360
}
360361

362+
impl<T> Default for BoxBlock<T> {
363+
fn default() -> Self {
364+
Self::new()
365+
}
366+
}
367+
361368
#[cfg(test)]
362369
mod tests {
363370
use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
371+
use std::ptr::addr_of_mut;
364372
use std::thread;
365373

366374
use super::*;
@@ -378,7 +386,7 @@ mod tests {
378386

379387
let block = unsafe {
380388
static mut BLOCK: BoxBlock<i32> = BoxBlock::new();
381-
&mut BLOCK
389+
addr_of_mut!(BLOCK).as_mut().unwrap()
382390
};
383391
MyBoxPool.manage(block);
384392

@@ -391,7 +399,7 @@ mod tests {
391399

392400
let block = unsafe {
393401
static mut BLOCK: BoxBlock<i32> = BoxBlock::new();
394-
&mut BLOCK
402+
addr_of_mut!(BLOCK).as_mut().unwrap()
395403
};
396404
MyBoxPool.manage(block);
397405

@@ -418,7 +426,7 @@ mod tests {
418426

419427
let block = unsafe {
420428
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
421-
&mut BLOCK
429+
addr_of_mut!(BLOCK).as_mut().unwrap()
422430
};
423431
MyBoxPool.manage(block);
424432

@@ -440,7 +448,7 @@ mod tests {
440448

441449
let block = unsafe {
442450
static mut BLOCK: BoxBlock<Zst4096> = BoxBlock::new();
443-
&mut BLOCK
451+
addr_of_mut!(BLOCK).as_mut().unwrap()
444452
};
445453
MyBoxPool.manage(block);
446454

@@ -467,11 +475,11 @@ mod tests {
467475

468476
MyBoxPool.manage(unsafe {
469477
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
470-
&mut BLOCK
478+
addr_of_mut!(BLOCK).as_mut().unwrap()
471479
});
472480
MyBoxPool.manage(unsafe {
473481
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
474-
&mut BLOCK
482+
addr_of_mut!(BLOCK).as_mut().unwrap()
475483
});
476484

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

501509
MyBoxPool.manage(unsafe {
502510
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
503-
&mut BLOCK
511+
addr_of_mut!(BLOCK).as_mut().unwrap()
504512
});
505513

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

535543
MyBoxPool.manage(unsafe {
536544
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
537-
&mut BLOCK
545+
addr_of_mut!(BLOCK).as_mut().unwrap()
538546
});
539547
MyBoxPool.manage(unsafe {
540548
static mut BLOCK: BoxBlock<MyStruct> = BoxBlock::new();
541-
&mut BLOCK
549+
addr_of_mut!(BLOCK).as_mut().unwrap()
542550
});
543551

544552
let boxed = MyBoxPool.alloc(MyStruct).ok().unwrap();

src/pool/object.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! let block: &'static mut ObjectBlock<[u8; 128]> = unsafe {
1515
//! // unlike the memory pool APIs, an initial value must be specified here
1616
//! static mut BLOCK: ObjectBlock<[u8; 128]>= ObjectBlock::new([0; 128]);
17-
//! &mut BLOCK
17+
//! addr_of_mut!(BLOCK).as_mut().unwrap()
1818
//! };
1919
//!
2020
//! // give object block to the pool
@@ -55,7 +55,7 @@
5555
//! let blocks: &'static mut [ObjectBlock<[u8; 128]>] = {
5656
//! const BLOCK: ObjectBlock<[u8; 128]> = ObjectBlock::new([0; 128]); // <=
5757
//! static mut BLOCKS: [ObjectBlock<[u8; 128]>; POOL_CAPACITY] = [BLOCK; POOL_CAPACITY];
58-
//! unsafe { &mut BLOCKS }
58+
//! unsafe { addr_of_mut!(BLOCK).as_mut().unwrap()S }
5959
//! };
6060
//!
6161
//! for block in blocks {
@@ -332,6 +332,7 @@ impl<T> ObjectBlock<T> {
332332
#[cfg(test)]
333333
mod tests {
334334
use core::sync::atomic::{self, AtomicUsize};
335+
use std::ptr::addr_of_mut;
335336

336337
use super::*;
337338

@@ -348,7 +349,7 @@ mod tests {
348349

349350
let block = unsafe {
350351
static mut BLOCK: ObjectBlock<i32> = ObjectBlock::new(1);
351-
&mut BLOCK
352+
addr_of_mut!(BLOCK).as_mut().unwrap()
352353
};
353354
MyObjectPool.manage(block);
354355

@@ -361,7 +362,7 @@ mod tests {
361362

362363
let block = unsafe {
363364
static mut BLOCK: ObjectBlock<i32> = ObjectBlock::new(1);
364-
&mut BLOCK
365+
addr_of_mut!(BLOCK).as_mut().unwrap()
365366
};
366367
MyObjectPool.manage(block);
367368

@@ -389,7 +390,7 @@ mod tests {
389390

390391
let block = unsafe {
391392
static mut BLOCK: ObjectBlock<MyStruct> = ObjectBlock::new(MyStruct);
392-
&mut BLOCK
393+
addr_of_mut!(BLOCK).as_mut().unwrap()
393394
};
394395
MyObjectPool.manage(block);
395396

@@ -411,7 +412,7 @@ mod tests {
411412

412413
let block = unsafe {
413414
static mut BLOCK: ObjectBlock<Zst4096> = ObjectBlock::new(Zst4096);
414-
&mut BLOCK
415+
addr_of_mut!(BLOCK).as_mut().unwrap()
415416
};
416417
MyObjectPool.manage(block);
417418

src/pool/treiber.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub trait Node: Sized {
3939
type Data;
4040

4141
fn next(&self) -> &AtomicPtr<Self>;
42+
43+
#[allow(dead_code)] // used conditionally
4244
fn next_mut(&mut self) -> &mut AtomicPtr<Self>;
4345
}
4446

0 commit comments

Comments
 (0)