pub struct FileLock { /* private fields */ }Expand description
File lock state machine. Wraps a raw fd and tracks the current lock level.
All transitions follow the legal state progression:
- UNLOCKED → SHARED (only valid transition from UNLOCKED)
- SHARED → RESERVED
- RESERVED → EXCLUSIVE (via PENDING internally)
- EXCLUSIVE/RESERVED → SHARED (downgrade)
- SHARED → UNLOCKED
Implementations§
Source§impl FileLock
impl FileLock
Acquire SHARED lock (for readers and initial open).
Multiple processes can hold SHARED simultaneously. Blocks if another process holds PENDING or EXCLUSIVE.
Sourcepub fn lock_reserved(&mut self, timeout: Duration) -> Result<()>
pub fn lock_reserved(&mut self, timeout: Duration) -> Result<()>
Acquire RESERVED lock (write intent — one at a time).
Signals that this process intends to write. Readers continue unimpeded. Only one RESERVED lock can exist at a time.
Retries with exponential backoff until the timeout expires,
then returns WriterLocked.
Sourcepub fn lock_exclusive(&mut self) -> Result<()>
pub fn lock_exclusive(&mut self) -> Result<()>
Escalate from RESERVED to EXCLUSIVE.
First acquires PENDING (blocks new readers), then waits for existing readers to drain, then acquires EXCLUSIVE.
This is a blocking operation — it waits until all existing SHARED locks are released.
Downgrade from EXCLUSIVE or RESERVED to SHARED.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FileLock
impl RefUnwindSafe for FileLock
impl Send for FileLock
impl Sync for FileLock
impl Unpin for FileLock
impl UnsafeUnpin for FileLock
impl UnwindSafe for FileLock
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more