Provides mutual exclusion on a file using
flock(2)
.
{
let _guard = fmutex::lock(path)?;
// do mutually exclusive stuff here
} // <-- `_guard` dropped here and the lock is released
match fmutex::try_lock(path)? {
Some(_guard) => {
// do mutually exclusive stuff here
} // <-- `_guard` dropped here and the lock is released
None => {
eprintln!("warn: the lock could not be acquired!");
}
}
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.