block_flock_step

Function block_flock_step 

Source
pub fn block_flock_step<P: AsRef<Path>>(
    path: P,
    mode: FlockMode,
    deadline: Instant,
    tick: Duration,
) -> Result<FlockWait>
Expand description

One deadline-bounded BLOCKING flock(2) cycle with a periodic re-evaluation tick.

Parks the calling thread in the kernel’s per-inode flock wait queue — the wake-latency primitive the polling loops lacked: the kernel wakes the waiter at release time, so a freed lock is picked up in microseconds, not at the next poll interval.

Returns:

  • FlockWait::Granted when the lock is granted,
  • FlockWait::Tick when tick elapses first (caller re-evaluates live state — e.g. a coordinator re-scanning for a fully-free alternative target — then typically calls again),
  • FlockWait::DeadlineExpired when deadline passes,
  • Err on open / unexpected-errno failures.

Mechanism: a thread-targeted CLOCK_MONOTONIC POSIX timer (DeadlineTimer) delivers SIGRTMIN+4 (no-op handler, no SA_RESTART) to this thread every tick (clamped to the remaining deadline budget), forcing the blocked flock to return EINTR; the step maps that to Tick or DeadlineExpired by the clock. The interval re-fire means a signal landing in the gap between arming and blocking cannot strand the waiter.