pub unsafe trait RawLock {
// Required methods
fn poison(&self);
unsafe fn raw_write(&self);
unsafe fn raw_try_write(&self) -> bool;
unsafe fn raw_unlock_write(&self);
unsafe fn raw_read(&self);
unsafe fn raw_try_read(&self) -> bool;
unsafe fn raw_unlock_read(&self);
}
Expand description
A raw lock type that may be locked and unlocked
§Safety
A deadlock must never occur. The unlock
method must correctly unlock the
data. The get_ptrs
method must be implemented correctly. The Output
must be unlocked when it is dropped.
Required Methods§
Sourcefn poison(&self)
fn poison(&self)
Causes all subsequent calls to the lock
function on this lock to
panic. This does not affect anything currently holding the lock.
Sourceunsafe fn raw_try_write(&self) -> bool
unsafe fn raw_try_write(&self) -> bool
Sourceunsafe fn raw_unlock_write(&self)
unsafe fn raw_unlock_write(&self)
Sourceunsafe fn raw_read(&self)
unsafe fn raw_read(&self)
Blocks until the data the lock protects can be safely read.
Some locks, but not all, will allow multiple readers at once. If
multiple readers are allowed for a Lockable
type, then the
Sharable
marker trait should be implemented.
§Safety
It is undefined behavior to use this without ownership or mutable
access to the ThreadKey
, which should last as long as the return
value is alive.
Sourceunsafe fn raw_try_read(&self) -> bool
unsafe fn raw_try_read(&self) -> bool
Returns true
if successful, false
otherwise.
Some locks, but not all, will allow multiple readers at once. If
multiple readers are allowed for a Lockable
type, then the
Sharable
marker trait should be implemented.
§Safety
It is undefined behavior to use this without ownership or mutable
access to the ThreadKey
, which should last as long as the return
value is alive.
Sourceunsafe fn raw_unlock_read(&self)
unsafe fn raw_unlock_read(&self)
Releases the lock after calling read
.
§Safety
It is undefined behavior to use this if the read lock is not acquired