1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*******************************************************************************
*
* Copyright (c) 2025 - 2026 Haixing Hu.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0.
*
******************************************************************************/
//! Ultra-light compare-and-swap primitives for hot `usize` state paths.
//!
//! This module provides [`FastCas`], a minimal executor over [`FastCasState`]
//! (`Atomic<usize>`). Use it when shared machine or protocol state fits in a
//! single integer code and you want **no allocation**, **no reporting hooks**,
//! and **retry logic that only reacts to CAS conflicts** (lost races), not
//! business validation failures.
//!
//! ## Compared with [`CasExecutor`](crate::CasExecutor)
//!
//! [`CasExecutor`](crate::CasExecutor) carries typed state `T`, optional timeouts, observability,
//! and richer outcomes. [`FastCas`] trades those features for predictable
//! overhead: the operation closure returns [`FastCasDecision`] and may run
//! **multiple times** after conflicts, so it must stay cheap and side-effect
//! free except through the returned decision.
//!
//! ## Operation shapes
//!
//! - [`FastCas::execute`] — full control via [`FastCasDecision`] (`Update` /
//! `Finish` / `Abort`).
//! - [`FastCas::update_by`] — convenience when you already express logic as
//! `Result<(next, output), error>`.
//! - [`FastCas::compare_update`] / [`FastCas::compare_update_with`] — a single
//! fixed transition `expected → next`; **one** atomic compare-and-swap (no
//! spin/yield policy).
//!
//! Retry policies ([`FastCasPolicy`]) apply to [`FastCas::execute`] and
//! [`FastCas::update_by`] only.
pub use FastCas;
pub use FastCasDecision;
pub use FastCasError;
pub use FastCasPolicy;
pub use FastCasState;
pub use FastCasSuccess;