rustls/lock.rs
1pub use std_lock::*;
2
3mod std_lock {
4 use std::sync::Mutex as StdMutex;
5 pub use std::sync::MutexGuard;
6
7 /// A wrapper around [`std::sync::Mutex`].
8 #[derive(Debug)]
9 pub struct Mutex<T> {
10 inner: StdMutex<T>,
11 }
12
13 impl<T> Mutex<T> {
14 /// Creates a new mutex in an unlocked state ready for use.
15 pub fn new(data: T) -> Self {
16 Self {
17 inner: StdMutex::new(data),
18 }
19 }
20
21 /// Acquires the mutex, blocking the current thread until it is able to do so.
22 ///
23 /// This will return `None` in the case the mutex is poisoned.
24 #[inline]
25 pub fn lock(&self) -> Option<MutexGuard<'_, T>> {
26 self.inner.lock().ok()
27 }
28 }
29}