Struct safe_lock::SafeLock[][src]

pub struct SafeLock { /* fields omitted */ }

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

impl Default for SafeLock[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.