Struct gstuff::FileLock

source ·
pub struct FileLock<'a> {
    pub lock_path: &'a dyn AsRef<Path>,
    pub ttl_sec: f64,
    pub file: File,
}
Expand description

Allows several threads or processes to compete for a shared resource by tracking resource ownership with a file.
If the lock file is older than ttl_sec then it is removed, allowing us to recover from a thread or process dying while holding the lock.

Fields

lock_path: &'a dyn AsRef<Path>

Filesystem path of the lock file.

ttl_sec: f64

The time in seconds after which an outdated lock file can be removed.

file: File

The owned lock file. Removed upon unlock.

Implementations

Tries to obtain a file lock.

Returns None if the file already exists and is recent enough.

The returned structure will automatically remove the lock file when dropped.

if let Some (lock) = try_s! (FileLock::lock (&"something.lock", 600.)) {
  // ... Your code here ...
  drop (lock)
}

Updates the modification time on the lock file. Compile on Linux only as UTIME_NOW and futimens is absent on MacOS.

Trait Implementations

Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.