Exclusive File Lease Manager (src/exclusive_file_lease.rs)

OpenBitFun · src/crates/services/services-core/src/exclusive_file_lease.rs · rust · MIT
infra, files, lang:rust, tag:concurrency, tag:locking

Ensures a single process holds a resource lock via the filesystem. Use this to prevent race conditions in multi-process applications requiring exclusive access.

// Source: https://github.com/GCWing/OpenBitFun | License: MIT | Copyright 2026 CWing
// Provided via justclaw.it.com; keep this notice with the code.
use crate::file_lock::{is_lock_contention, FileLock, FileLockError, FileLockMode};
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex, OnceLock, Weak};

/// Holds one shared resource for a single process at a time.
///
/// Where `session::write_lock` guards one Session, this guards a resource that
/// an owning process keeps for its whole lifetime — a scheduler loop, a store
/// writer. Ownership is represented by the OS lock, not by file existence:
/// the lock file may remain on disk after the lease is released, and a stale
/// file never implies ownership.
pub struct ExclusiveFileLease {
    inner: A

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key