pub struct SafeLock(/* private fields */);
Expand description
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§
Source§impl SafeLock
impl SafeLock
pub const fn new() -> SafeLock
Sourcepub fn lock(&self) -> Option<SafeLockGuard<'_>>
pub fn lock(&self) -> Option<SafeLockGuard<'_>>
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.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SafeLock
impl RefUnwindSafe for SafeLock
impl Send for SafeLock
impl Sync for SafeLock
impl Unpin for SafeLock
impl UnwindSafe for SafeLock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more