async_stm/
lib.rs

1// For benchmarks.
2#![cfg_attr(feature = "unstable", feature(test))]
3
4#[cfg(feature = "unstable")]
5extern crate test as etest;
6
7mod ops;
8mod transaction;
9mod vars;
10mod version;
11
12/// Auxiliary transactions.
13pub mod auxtx;
14
15/// [TVar] is the public interface to lift data into the transactional
16/// context for subsequent read and write operations.
17pub use vars::TVar;
18
19/// The primary verbs to interact with STM transactions.
20pub use ops::{
21    abort, atomically, atomically_aux, atomically_or_err, atomically_or_err_aux, guard, or, retry,
22};
23
24/// Transactional queue implementations.
25#[cfg(feature = "queues")]
26pub mod queues;
27
28/// Transaction shortcutting signals handled by the STM framework.
29pub enum StmControl {
30    /// The transaction failed because a value changed.
31    /// It can be retried straight away.
32    Failure,
33    /// Retry was called and now the transaction has
34    /// to wait until at least one of the variables it
35    /// read have changed, before being retried.
36    Retry,
37}
38
39/// STM error extended with the ability to abort the transaction
40/// with an error. It is separate so that we rest assured
41/// that [atomically] will not return an error, that only
42/// [atomically_or_err] allows abortions.
43pub enum StmError<E> {
44    /// Regular error.
45    Control(StmControl),
46    /// Abort the transaction and return an error.
47    Abort(E),
48}
49
50/// Conversion to allow mixing methods returning [Stm]
51/// with ones returning [StmResult] using the `?` operator.
52impl<E> From<StmControl> for StmError<E> {
53    fn from(e: StmControl) -> Self {
54        StmError::Control(e)
55    }
56}
57
58/// Type returned by STM methods that cannot be aborted,
59/// the only reason they can fail is to be retried.
60pub type Stm<T> = Result<T, StmControl>;
61
62/// Type returned by STM methods that can be aborted with an error.
63///
64/// Such methods must be executed with [atomically_or_err].
65pub type StmResult<T, E> = Result<T, StmError<E>>;
66
67#[cfg(test)]
68mod test;