pub struct SharedRWLock { /* private fields */ }Implementations§
Sourcepub fn create(path: impl AsRef<Path>) -> Result<Self, RWLockError>
pub fn create(path: impl AsRef<Path>) -> Result<Self, RWLockError>
Obtain the lock at path, initializing it if it does not yet exist and
attaching to it if it does. Attaching leaves a held writer flag in
place. reset reinitializes.
Sourcepub fn reset(path: impl AsRef<Path>) -> Result<Self, RWLockError>
pub fn reset(path: impl AsRef<Path>) -> Result<Self, RWLockError>
Reinitialize the lock at path: the header is truncated and zeroed,
discarding any state a live holder owns. For a caller that owns the
path.
Sourcepub fn create_or_open(path: impl AsRef<Path>) -> Result<Self, RWLockError>
pub fn create_or_open(path: impl AsRef<Path>) -> Result<Self, RWLockError>
Open the lock at path, creating it if it does not exist, without a
window in which two callers can both create it.
create truncates and zeroes the header, so a second
caller running it against a live lock clears a writer flag another
holder owns and mutual exclusion is silently lost. An exists-then-create
check does not close that: the check and the create are separate steps.
Here exactly one caller wins an exclusive create_new and initialises;
the rest open and wait for the magic to appear.
Use this for any lock a peer may reach first. create
stays the right call only when the caller knows it owns the path.
pub fn open(path: impl AsRef<Path>) -> Result<Self, RWLockError>
Sourcepub fn try_read_lock(&self) -> Result<ReadGuard<'_>, RWLockError>
pub fn try_read_lock(&self) -> Result<ReadGuard<'_>, RWLockError>
Try to acquire a read lock without blocking.
Sourcepub fn read_lock(&self) -> ReadGuard<'_>
pub fn read_lock(&self) -> ReadGuard<'_>
Acquire a read lock, blocking with backoff until available. Writer-priority: blocks if any writer is active OR waiting.
Sourcepub fn try_write_lock(&self) -> Result<WriteGuard<'_>, RWLockError>
pub fn try_write_lock(&self) -> Result<WriteGuard<'_>, RWLockError>
Try to acquire a write lock without blocking.
Sourcepub fn write_lock(&self) -> WriteGuard<'_>
pub fn write_lock(&self) -> WriteGuard<'_>
Acquire a write lock, blocking until available. Registers as “waiting” so new readers will block.
Sourcepub fn reader_count(&self) -> u32
pub fn reader_count(&self) -> u32
Number of active readers (observational; may race).
Sourcepub fn has_writer(&self) -> bool
pub fn has_writer(&self) -> bool
True if a writer currently holds the lock.
Sourcepub fn waiting_writers(&self) -> u32
pub fn waiting_writers(&self) -> u32
Number of writers currently waiting for the lock.
Sourcepub fn release_read_for_blocking(&self)
pub fn release_read_for_blocking(&self)
Public hook for the BlockingRWLock wrapper to mirror the
inner ReadGuard::drop semantics after the wrapper’s own
guard runs (the wrapper mem::forgets the inner guard so it
can interleave a wake call between the state release and the
guard’s destructor).
Sourcepub fn release_write_for_blocking(&self)
pub fn release_write_for_blocking(&self)
Public hook for the BlockingRWLock wrapper; mirror of
WriteGuard::drop.