Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvements for documentation #528

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 72 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,84 @@
//!
//! List of currently implemented data structures:
#![cfg_attr(
any(arm_llsc, target_pointer_width = "32", target_pointer_width = "64"),
doc = "- [`Arc`](pool::arc::Arc) -- like `std::sync::Arc` but backed by a lock-free memory pool rather than `#[global_allocator]`"
any(
arm_llsc,
all(
target_pointer_width = "32",
any(target_has_atomic = "64", feature = "portable-atomic")
),
all(
target_pointer_width = "64",
any(
all(target_has_atomic = "128", feature = "nightly"),
feature = "portable-atomic"
)
)
),
doc = "- [Arc][pool::arc::Arc] -- like `std::sync::Arc` but backed by a lock-free memory pool rather than [global_allocator]"
)]
#![cfg_attr(
any(
arm_llsc,
all(
target_pointer_width = "32",
any(target_has_atomic = "64", feature = "portable-atomic")
),
all(
target_pointer_width = "64",
any(
all(target_has_atomic = "128", feature = "nightly"),
feature = "portable-atomic"
)
)
),
doc = "- [Box][pool::boxed::Box] -- like `std::boxed::Box` but backed by a lock-free memory pool rather than [global_allocator]"
)]
#![cfg_attr(
any(arm_llsc, target_pointer_width = "32", target_pointer_width = "64"),
doc = "- [`Box`](pool::boxed::Box) -- like `std::boxed::Box` but backed by a lock-free memory pool rather than `#[global_allocator]`"
any(
arm_llsc,
all(
target_pointer_width = "32",
any(target_has_atomic = "64", feature = "portable-atomic")
),
all(
target_pointer_width = "64",
any(
all(target_has_atomic = "128", feature = "nightly"),
feature = "portable-atomic"
)
)
),
doc = "- [Arc][pool::arc::Arc] -- like `std::sync::Arc` but backed by a lock-free memory pool rather than [global_allocator]"
)]
//! - [`BinaryHeap`] -- priority queue
//! - [`Deque`] -- double-ended queue
//! - [`HistoryBuffer`] -- similar to a write-only ring buffer
//! - [`IndexMap`] -- hash table
//! - [`IndexSet`] -- hash set
//! - [`LinearMap`]
#![cfg_attr(
any(arm_llsc, target_pointer_width = "32", target_pointer_width = "64"),
doc = "- [`Object`](pool::object::Object) -- objects managed by an object pool"
any(
arm_llsc,
all(
target_pointer_width = "32",
any(target_has_atomic = "64", feature = "portable-atomic")
),
all(
target_pointer_width = "64",
any(
all(target_has_atomic = "128", feature = "nightly"),
feature = "portable-atomic"
)
)
),
doc = "- [Object](pool::object::Object) -- objects managed by an object pool"
)]
//! - [`sorted_linked_list::SortedLinkedList`]
//! - [`String`]
//! - [`Vec`]
//! - [BinaryHeap] -- priority queue
//! - [Deque] -- double-ended queue
//! - [HistoryBuffer] -- similar to a write-only ring buffer
//! - [IndexMap] -- hash table
//! - [IndexSet] -- hash set
//! - [LinearMap]
//! - [sorted_linked_list::SortedLinkedList]
//! - [String]
//! - [Vec]
//! - [`mpmc::Q*`](mpmc) -- multiple producer multiple consumer lock-free queue
//! - [`spsc::Queue`] -- single producer single consumer lock-free queue
//! - [spsc] and [spsc::Queue] -- single producer single consumer lock-free queue
//!
//! # Minimum Supported Rust Version (MSRV)
//!
Expand Down
18 changes: 12 additions & 6 deletions src/spsc.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
//! A fixed capacity Single Producer Single Consumer (SPSC) queue.
//! # A fixed capacity Single Producer Single Consumer (SPSC) queue.
//!
//! Implementation based on <https://www.codeproject.com/Articles/43510/Lock-Free-Single-Producer-Single-Consumer-Circular>
//!
//! # Portability
//! ## Portability
//!
//! This module requires CAS atomic instructions which are not available on all architectures
//! (e.g. ARMv6-M (`thumbv6m-none-eabi`) and MSP430 (`msp430-none-elf`)). These atomics can be
//! emulated however with [`portable-atomic`](https://crates.io/crates/portable-atomic), which is
//! enabled with the `cas` feature and is enabled by default for `thumbv6m-none-eabi` and `riscv32`
//! targets.
//!
//! # Examples
//! ## Examples
//!
//! - `Queue` can be used as a plain queue
//! - [Queue] can be used as a plain queue
//!
//! ```
//! use heapless::spsc::Queue;
Expand All @@ -27,12 +27,16 @@
//! assert_eq!(rb.dequeue(), Some(0));
//! ```
//!
//! - `Queue` can be `split` and then be used in Single Producer Single Consumer mode.
//! - [Queue] can be [Queue::split] and then be used in Single Producer Single Consumer mode.
//!
//! "no alloc" applications can create a `&'static mut` reference to a `Queue` -- using a static
//! variable -- and then `split` it: this consumes the static reference. The resulting `Consumer`
//! and `Producer` can then be moved into different execution contexts (threads, interrupt handlers,
//! etc.)
//! etc.).
//!
//! Alternatively, you can also create the Queue statically in the global scope by wrapping it with
//! a [static_cell](https://docs.rs/static_cell/latest/static_cell/)
//!
//!
//! ```
//! use heapless::spsc::{Producer, Queue};
Expand All @@ -43,6 +47,8 @@
//! }
//!
//! fn main() {
//! // Alternatively, use something like `static_cell` to create the `Queue` in the global
//! // scope.
//! let queue: &'static mut Queue<Event, 4> = {
//! static mut Q: Queue<Event, 4> = Queue::new();
//! unsafe { &mut Q }
Expand Down
Loading