lock_freedom/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![warn(missing_docs)]
3//! A crate providing lock-free data structures and a solution for the "ABA
4//! problem" related to pointers.
5//!
6//! The incinerator is the API which tries to solve the "ABA problem" when
7//! related to pointer dropping. With incinerator, every thread has a local
8//! garbage list. Dropping a shared object consist of first removing the pointer
9//! from the shared context, then adding the pointer to the garbage list.
10//! A "pause counter" is checked. If the counter is zero, then the whole list
11//! is deleted, otherwise, the list will only be deleted later.
12//!
13//! This counter is counting how many times the incinerator was asked to
14//! "pause". A thread may pause the incinerator to load and use the shared
15//! pointer, and this is why it is important to remove the pointer from the
16//! shared context before deleting. Previous version of lockfree used a global
17//! incinerator. Currently, a per-object incinerator is used.
18//!
19//! This crate is under development, and there are plans for some structures.
20//! We have:
21//! - `[x]` [Per-Object Thread-Local Storage](tls::ThreadLocal)
22//! - `[x]` [Channels (SPSC, MPSC, SPMC, MPMC)](channel)
23//! - `[x]` [Map](map::Map)
24//! - `[x]` [Set](set::Set)
25//! - `[x]` [Stack](stack::Stack)
26//! - `[x]` [Queue](queue::Queue)
27//! - `[ ]` Deque
28//!
29//! # Performance Guide
30//! In order to achieve a better time performance with lockfree, it is
31//! recommended to avoid global locking stuff like heap allocation.
32
33extern crate alloc;
34
35pub(crate) mod owned_alloc;
36/// Provides convenient re-exports.
37pub mod prelude;
38/// Incinerator API. The purpouse of this module is to solve the "ABA problem"
39/// related to pointers while still being lock-free. See documentation of the
40/// inner type for more details.
41#[macro_use]
42#[cfg(feature = "std")]
43pub mod incin;
44
45/// A wait-free per-object Thread Local Storage (TLS).
46#[cfg(feature = "std")]
47pub mod tls;
48
49/// A lock-free queue.
50#[cfg(feature = "std")]
51pub mod queue;
52
53/// A lock-free stack.
54#[cfg(feature = "std")]
55pub mod stack;
56
57/// A lock-free map.
58#[cfg(feature = "std")]
59pub mod map;
60
61/// A lock-free set.
62#[cfg(feature = "std")]
63pub mod set;
64
65/// Collection of lock-free FIFO channels. These channels are fully asynchronous
66/// and their receivers do not provide any sort of `wait-for-message` operation.
67/// It would be blocking otherwise, thus not lock-free. If you need such a
68/// mechanism, consider using this channel with a
69/// [`Condvar`](std::sync::Condvar) or using things like
70/// [`thread::park`](std::thread::park) (not lock-free).
71#[cfg(feature = "std")]
72pub mod channel;
73
74/// A shared removable value. No extra allocation is necessary.
75pub mod removable;
76
77#[allow(dead_code)]
78mod ptr;