instance_copy_on_write/
lib.rs

1/*-
2 * instance-copy-on-write - a synchronization primitive based on copy-on-write.
3 * 
4 * Copyright (C) 2025 Aleksandr Morozov alex@
5 * 
6 * The scram-rs crate can be redistributed and/or modified
7 * under the terms of either of the following licenses:
8 *
9 *   1. the Mozilla Public License Version 2.0 (the “MPL”) OR
10 *                     
11 *   2. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016
12 */
13
14 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
15 pub enum ICoWLockTypes
16 {
17    Atomic,
18    RwLock,
19 }
20
21/// Errors which may be returned.
22#[derive(Copy, Clone, Debug, PartialEq, Eq)]
23pub enum ICoWError
24{
25    /// An attempt to write to the instance using non exclusive copy-on-write operation
26    /// while the exclusive is still going.
27    ExclusiveLockPending,
28
29    /// Is issued if "exponential backoff has completed and blocking the thread is advised".
30    WouldBlock,
31
32    /// Duplicate write operation prevented.
33    AlreadyUpdated,
34
35    /// Race condition on the exclusive lock.
36    RaceCondition
37}
38
39extern crate crossbeam_utils;
40extern crate crossbeam_deque;
41
42/// A lightweight CoW implementation.
43#[cfg(all(target_has_atomic = "ptr", feature = "prefer_atomic"))]
44pub mod cow;
45
46/// A RwLock based copy-on-write.
47#[cfg(any(not(target_has_atomic = "ptr"), not(feature = "prefer_atomic")))]
48pub mod cow_mutex;
49
50#[cfg(all(target_has_atomic = "ptr", feature = "prefer_atomic"))]
51pub use cow::{ICoW, ICoWRead, ICoWCopy, ICoWLock};
52
53#[cfg(any(not(target_has_atomic = "ptr"), not(feature = "prefer_atomic")))]
54pub use cow_mutex::{ICoW, ICoWRead, ICoWCopy, ICoWLock};