From fbaad4df93b163d047859b510338ce53360ce9f1 Mon Sep 17 00:00:00 2001 From: Alexey Gerasev Date: Fri, 27 Sep 2024 17:50:16 +0700 Subject: [PATCH] Add portable-atomic feature --- Cargo.toml | 4 ++-- README.md | 2 +- scripts/test.sh | 1 + src/rb/shared.rs | 3 +++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ddab21b..9fc5aeb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,14 +26,14 @@ license.workspace = true [features] default = ["std"] -std = ["alloc", "portable-atomic/std"] +std = ["alloc", "portable-atomic?/std"] alloc = [] bench = [] test_local = [] [dependencies] crossbeam-utils = { version = "0.8", default-features = false } -portable-atomic = "1" +portable-atomic = { version = "1", default-features = false, optional = true } [dev-dependencies] once_mut = "0.1.0" diff --git a/README.md b/README.md index 4f5137e..8b18656 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Lock-free SPSC FIFO ring buffer with direct access to inner data. + Different types of buffers and underlying storages. + Can be used without `std` and even without `alloc` (using only statically-allocated memory). + Async and blocking versions (see [this section](#derived-crates)). -+ Uses the `portable-atomic` crate to allow usage on smaller systems without CAS operations. ++ Can optionally use the [`portable-atomic`](https://crates.io/crates/portable-atomic) crate to allow usage on smaller systems without CAS operations. # Usage diff --git a/scripts/test.sh b/scripts/test.sh index 5259ea1..0778e55 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -2,6 +2,7 @@ cargo test && \ cargo test --features test_local && \ +cargo test --features portable-atomic && \ cargo check --no-default-features --features alloc && \ cargo check --no-default-features && \ cd async && \ diff --git a/src/rb/shared.rs b/src/rb/shared.rs index 0687964..abada88 100644 --- a/src/rb/shared.rs +++ b/src/rb/shared.rs @@ -12,12 +12,15 @@ use crate::{ }; #[cfg(feature = "alloc")] use alloc::{boxed::Box, sync::Arc}; +#[cfg(not(feature = "portable-atomic"))] +use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use core::{ mem::{ManuallyDrop, MaybeUninit}, num::NonZeroUsize, ptr, }; use crossbeam_utils::CachePadded; +#[cfg(feature = "portable-atomic")] use portable_atomic::{AtomicBool, AtomicUsize, Ordering}; /// Ring buffer that can be shared between threads.