async_fifo/
lib.rs

1//! This crate implements multiple lock-free structures for object transfers:
2//! 
3//! - fully-featured MPMC channels (see [`channel::new()`])
4//! - small one-shot SPSC channels (see [`channel::oneshot()`])
5//! - an atomic equivalent to `Box<T>` (see [`slot::Slot`])
6//! 
7//! All of these structures are synchronized without any locks and without spinning/yielding.
8//! This crate is compatible with `no_std` targets, except for the `*_blocking` methods.
9//!
10//! (All items of the `channel` module are re-exported here at the root.)
11
12#![no_std]
13
14#[cfg(any(test, feature = "blocking"))]
15extern crate std;
16
17extern crate alloc;
18
19use core::sync::atomic::AtomicPtr;
20use core::sync::atomic::Ordering::{SeqCst, Relaxed};
21
22mod tests;
23
24/// Atomic and asynchronous slots
25pub mod slot;
26
27pub mod fifo;
28
29pub mod channel;
30
31pub use channel::*;
32
33#[cfg(feature = "blocking")]
34mod fn_block_on;
35
36#[cfg(feature = "blocking")]
37#[doc(hidden)]
38pub use fn_block_on::block_on;
39
40fn try_swap_ptr<T>(atomic_ptr: &AtomicPtr<T>, old: *mut T, new: *mut T) -> bool {
41    atomic_ptr.compare_exchange(old, new, SeqCst, Relaxed).is_ok()
42}