Skip to content

Commit 346525f

Browse files
authored
Merge pull request #528 from us-irs/docs-improvements
improvements for documentation
2 parents 3f9f5a1 + 0f20e40 commit 346525f

File tree

2 files changed

+84
-22
lines changed

2 files changed

+84
-22
lines changed

src/lib.rs

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,84 @@
4343
//!
4444
//! List of currently implemented data structures:
4545
#![cfg_attr(
46-
any(arm_llsc, target_pointer_width = "32", target_pointer_width = "64"),
47-
doc = "- [`Arc`](pool::arc::Arc) -- like `std::sync::Arc` but backed by a lock-free memory pool rather than `#[global_allocator]`"
46+
any(
47+
arm_llsc,
48+
all(
49+
target_pointer_width = "32",
50+
any(target_has_atomic = "64", feature = "portable-atomic")
51+
),
52+
all(
53+
target_pointer_width = "64",
54+
any(
55+
all(target_has_atomic = "128", feature = "nightly"),
56+
feature = "portable-atomic"
57+
)
58+
)
59+
),
60+
doc = "- [Arc][pool::arc::Arc] -- like `std::sync::Arc` but backed by a lock-free memory pool rather than [global_allocator]"
61+
)]
62+
#![cfg_attr(
63+
any(
64+
arm_llsc,
65+
all(
66+
target_pointer_width = "32",
67+
any(target_has_atomic = "64", feature = "portable-atomic")
68+
),
69+
all(
70+
target_pointer_width = "64",
71+
any(
72+
all(target_has_atomic = "128", feature = "nightly"),
73+
feature = "portable-atomic"
74+
)
75+
)
76+
),
77+
doc = "- [Box][pool::boxed::Box] -- like `std::boxed::Box` but backed by a lock-free memory pool rather than [global_allocator]"
4878
)]
4979
#![cfg_attr(
50-
any(arm_llsc, target_pointer_width = "32", target_pointer_width = "64"),
51-
doc = "- [`Box`](pool::boxed::Box) -- like `std::boxed::Box` but backed by a lock-free memory pool rather than `#[global_allocator]`"
80+
any(
81+
arm_llsc,
82+
all(
83+
target_pointer_width = "32",
84+
any(target_has_atomic = "64", feature = "portable-atomic")
85+
),
86+
all(
87+
target_pointer_width = "64",
88+
any(
89+
all(target_has_atomic = "128", feature = "nightly"),
90+
feature = "portable-atomic"
91+
)
92+
)
93+
),
94+
doc = "- [Arc][pool::arc::Arc] -- like `std::sync::Arc` but backed by a lock-free memory pool rather than [global_allocator]"
5295
)]
53-
//! - [`BinaryHeap`] -- priority queue
54-
//! - [`Deque`] -- double-ended queue
55-
//! - [`HistoryBuffer`] -- similar to a write-only ring buffer
56-
//! - [`IndexMap`] -- hash table
57-
//! - [`IndexSet`] -- hash set
58-
//! - [`LinearMap`]
5996
#![cfg_attr(
60-
any(arm_llsc, target_pointer_width = "32", target_pointer_width = "64"),
61-
doc = "- [`Object`](pool::object::Object) -- objects managed by an object pool"
97+
any(
98+
arm_llsc,
99+
all(
100+
target_pointer_width = "32",
101+
any(target_has_atomic = "64", feature = "portable-atomic")
102+
),
103+
all(
104+
target_pointer_width = "64",
105+
any(
106+
all(target_has_atomic = "128", feature = "nightly"),
107+
feature = "portable-atomic"
108+
)
109+
)
110+
),
111+
doc = "- [Object](pool::object::Object) -- objects managed by an object pool"
62112
)]
63-
//! - [`sorted_linked_list::SortedLinkedList`]
64-
//! - [`String`]
65-
//! - [`Vec`]
113+
//! - [BinaryHeap] -- priority queue
114+
//! - [Deque] -- double-ended queue
115+
//! - [HistoryBuffer] -- similar to a write-only ring buffer
116+
//! - [IndexMap] -- hash table
117+
//! - [IndexSet] -- hash set
118+
//! - [LinearMap]
119+
//! - [sorted_linked_list::SortedLinkedList]
120+
//! - [String]
121+
//! - [Vec]
66122
//! - [`mpmc::Q*`](mpmc) -- multiple producer multiple consumer lock-free queue
67-
//! - [`spsc::Queue`] -- single producer single consumer lock-free queue
123+
//! - [spsc] and [spsc::Queue] -- single producer single consumer lock-free queue
68124
//!
69125
//! # Minimum Supported Rust Version (MSRV)
70126
//!

src/spsc.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
//! A fixed capacity Single Producer Single Consumer (SPSC) queue.
1+
//! # A fixed capacity Single Producer Single Consumer (SPSC) queue.
22
//!
33
//! Implementation based on <https://www.codeproject.com/Articles/43510/Lock-Free-Single-Producer-Single-Consumer-Circular>
44
//!
5-
//! # Portability
5+
//! ## Portability
66
//!
77
//! This module requires CAS atomic instructions which are not available on all architectures
88
//! (e.g. ARMv6-M (`thumbv6m-none-eabi`) and MSP430 (`msp430-none-elf`)). These atomics can be
99
//! emulated however with [`portable-atomic`](https://crates.io/crates/portable-atomic), which is
1010
//! enabled with the `cas` feature and is enabled by default for `thumbv6m-none-eabi` and `riscv32`
1111
//! targets.
1212
//!
13-
//! # Examples
13+
//! ## Examples
1414
//!
15-
//! - `Queue` can be used as a plain queue
15+
//! - [Queue] can be used as a plain queue
1616
//!
1717
//! ```
1818
//! use heapless::spsc::Queue;
@@ -27,12 +27,16 @@
2727
//! assert_eq!(rb.dequeue(), Some(0));
2828
//! ```
2929
//!
30-
//! - `Queue` can be `split` and then be used in Single Producer Single Consumer mode.
30+
//! - [Queue] can be [Queue::split] and then be used in Single Producer Single Consumer mode.
3131
//!
3232
//! "no alloc" applications can create a `&'static mut` reference to a `Queue` -- using a static
3333
//! variable -- and then `split` it: this consumes the static reference. The resulting `Consumer`
3434
//! and `Producer` can then be moved into different execution contexts (threads, interrupt handlers,
35-
//! etc.)
35+
//! etc.).
36+
//!
37+
//! Alternatively, you can also create the Queue statically in the global scope by wrapping it with
38+
//! a [static_cell](https://docs.rs/static_cell/latest/static_cell/)
39+
//!
3640
//!
3741
//! ```
3842
//! use heapless::spsc::{Producer, Queue};
@@ -43,6 +47,8 @@
4347
//! }
4448
//!
4549
//! fn main() {
50+
//! // Alternatively, use something like `static_cell` to create the `Queue` in the global
51+
//! // scope.
4652
//! let queue: &'static mut Queue<Event, 4> = {
4753
//! static mut Q: Queue<Event, 4> = Queue::new();
4854
//! unsafe { &mut Q }

0 commit comments

Comments
 (0)