pub struct StateLock { /* private fields */ }Expand description
An acquired state lock. The underlying file descriptor holds an exclusive flock; releasing happens automatically on drop (fd close).
The lock file is intentionally never unlinked — doing so during acquisition would allow two processes to each hold flock on different inodes.
Implementations§
Source§impl StateLock
impl StateLock
Sourcepub fn acquire(lock_path: &Path, timeout_ms: u64) -> Result<Self, WorktreeError>
pub fn acquire(lock_path: &Path, timeout_ms: u64) -> Result<Self, WorktreeError>
Acquire the state lock with full-jitter exponential backoff.
Backoff: sleep_ms = random(0, min(2000, 10 * 2^attempt)), capped at
15 attempts (~30s worst case).
Correctness: mutual exclusion is provided by the OS flock primitive, which auto-releases when the holding process dies. The payload in the lock file is informational (helps humans see who holds the lock). We never unlink the lock file during acquisition — that would create a two-inode race where two processes each hold flock on a different inode.
Auto Trait Implementations§
impl Freeze for StateLock
impl RefUnwindSafe for StateLock
impl Send for StateLock
impl Sync for StateLock
impl Unpin for StateLock
impl UnsafeUnpin for StateLock
impl UnwindSafe for StateLock
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