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
52
53
54
55
56
57
58
59
60
61
62
63
64
//! Backend trait for raw mutex implementations.
//!
//! Surelock is generic over any locking backend that implements
//! [`RawMutex`]. The trait uses a GAT-based guard -- `lock()` returns
//! a guard whose `Drop` releases the lock. No separate `unlock()`
//! method.
//!
//! # Built-in Backends
//!
//! - [`StdMutex`](std_mutex::StdMutex): wraps `std::sync::Mutex<()>`
//! (behind the `std` feature, which is the default).
//!
//! # `lock_api` Interop
//!
//! Enable the `lock-api` feature for a blanket impl that bridges any
//! `lock_api::RawMutex` implementation (`parking_lot`, `spin`, etc.)
//! to surelock's trait. No newtype wrappers needed.
/// A raw mutual exclusion primitive.
///
/// Implementations provide the low-level lock operations that
/// [`Mutex`](crate::mutex::Mutex) delegates to. Unlocking happens
/// by dropping the associated [`Guard`](RawMutex::Guard) type --
/// there is no separate `unlock()` method.
///
/// # Safety
///
/// Implementations must guarantee that:
/// - `lock()` blocks until the lock is acquired exclusively.
/// - A successful `lock()` or `try_lock()` returns a guard that
/// releases the lock on drop.
/// - While the guard is alive, no other thread can acquire the lock.
/// - The implementation is thread-safe.
pub unsafe