1 unstable release
0.1.0 | Feb 9, 2022 |
---|
#1139 in Filesystem
648 downloads per month
Used in 2 crates
7KB
79 lines
fmutex
Provides mutual exclusion on a file using
flock(2)
.
Usage
lock()
{
let _guard = fmutex::lock(path)?;
// do mutually exclusive stuff here
} // <-- `_guard` dropped here and the lock is released
try_lock()
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!");
}
}
License
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.
Dependencies
~44KB