Struct safe_lock::SafeLock [−][src]
A lock.
See lock
.
This is not a fair lock. If multiple threads acquire the lock in loops, some may never acquire it.
Example
Make some tests run sequentially so they don’t interfere with each other:
use safe_lock::SafeLock;
static LOCK: SafeLock = SafeLock::new();
[#test]
fn test1() {
let _guard = LOCK.lock();
// ...
}
[#test]
fn test2() {
let _guard = LOCK.lock();
// ...
}
Implementations
impl SafeLock
[src]
#[must_use]pub const fn new() -> SafeLock
[src]
#[must_use]pub fn lock(&self) -> Option<SafeLockGuard<'_>>
[src]
Waits until the lock is free, then acquires the lock.
Multiple threads can call lock
but only one will acquire the lock
and return.
Drop the returned SafeLockGuard
to release the lock.
This is not a fair lock. If multiple threads acquire the lock in loops, some may never acquire it.
Uses
Ordering::Acquire
to acquire the lock and
Ordering::Release
to release it, so the lock orders operations on other atomic values.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for SafeLock
impl Send for SafeLock
impl Sync for SafeLock
impl Unpin for SafeLock
impl UnwindSafe for SafeLock
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,