Struct Lock
pub struct Lock { /* private fields */ }
threading
only.Expand description
A basic locking object.
A Lock
behaves like a Mutex, but carries no data.
This is supposed to be used to implement other locking primitives.
Implementations§
§impl Lock
impl Lock
pub const fn new_locked() -> Lock
pub const fn new_locked() -> Lock
Creates new locked Lock.
pub fn acquire(&self)
pub fn acquire(&self)
Get this lock (blocking).
If the lock was unlocked, it will be locked and the function returns. If the lock was locked, this function will block the current thread until the lock gets unlocked elsewhere.
§Panics
Panics if this is called outside of a thread context.
pub fn try_acquire(&self) -> bool
pub fn try_acquire(&self) -> bool
Get the lock (non-blocking).
If the lock was unlocked, it will be locked and the function returns true. If the lock was locked, the function returns false
pub fn release(&self)
pub fn release(&self)
Releases the lock.
If the lock was locked, and there were waiters, the first waiter will be woken up. If the lock was locked and there were no waiters, the lock will be unlocked. If the lock was not locked, the function just returns.