pub struct ScopedLock { /* private fields */ }Expand description
A non-blocking cross-process exclusive lock used to serialise operations on a path-keyed resource (a workspace, a per-repo directory).
Unlike ManifestLock (which blocks on contention because the critical
section is small and cooperating), ScopedLock uses try_lock_write and
surfaces the busy condition to the caller. Callers decide whether to
fail fast or retry.
The lock file is created (O_CREAT) if missing and kept open for the
lifetime of the struct. A .lock suffix is conventional but not required
— any path will do. The lock is released on drop.
§Layering vs ManifestLock
ManifestLock wraps a blocking read/write critical section around a
manifest append path. ScopedLock is a try-lock guard held for an entire
operation (e.g. sync::run, GixBackend::checkout) where waiting would
be the wrong UX — the user likely launched two processes by accident and
needs to see the collision, not block on a second terminal they forgot
about.
Implementations§
Source§impl ScopedLock
impl ScopedLock
Sourcepub fn open(lock_path: &Path) -> Result<Self>
pub fn open(lock_path: &Path) -> Result<Self>
Open (and create if missing) the sidecar lock file at lock_path.
Does not acquire the lock — call ScopedLock::try_acquire.
§Errors
Returns any io::Error from OpenOptions::open.
Sourcepub fn acquire(&mut self) -> Result<RwLockWriteGuard<'_, File>>
pub fn acquire(&mut self) -> Result<RwLockWriteGuard<'_, File>>
Acquire the exclusive write lock, blocking until it is free.
Use for per-resource serialisation where the right behaviour under
contention is to wait (e.g. two syncs both wanting to fetch the
same clone — the second simply runs after the first finishes).
§Errors
Propagates any OS-level lock error from fd-lock.
Sourcepub fn try_acquire(&mut self) -> Result<Option<RwLockWriteGuard<'_, File>>>
pub fn try_acquire(&mut self) -> Result<Option<RwLockWriteGuard<'_, File>>>
Try to acquire the exclusive write lock without blocking.
Returns Ok(Some(guard)) on success, Ok(None) if another process /
thread already holds the lock, or Err(e) on an unexpected OS error.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ScopedLock
impl RefUnwindSafe for ScopedLock
impl Send for ScopedLock
impl Sync for ScopedLock
impl Unpin for ScopedLock
impl UnsafeUnpin for ScopedLock
impl UnwindSafe for ScopedLock
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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