Expand description
Repository locking for concurrent access.
RepoLock guarantees three invariants:
- Cross-process exclusion via
flock(2)on a lock file. - Cross-thread, same-process exclusion: two threads never both hold the write lock.
- Same-thread reentrancy: the owning thread may re-acquire the write lock any number of times without blocking.
The reentrancy invariant matters because flock(2) locks attach to the open
file description, not the process: a single thread that opens the lock file
twice and calls flock on the second fd blocks forever on its own first
lock. The canonical write lock is taken at the top of an import and then
re-taken by downstream writers on the same thread, so a non-reentrant
primitive self-deadlocks. We therefore hold the flock once on the outermost
acquisition and gate intra-process access through a per-lock-path registry.