Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rossmacarthur/fmutex
Provides mutual exclusion on a file using flock(2)
https://github.com/rossmacarthur/fmutex
Last synced: about 2 months ago
JSON representation
Provides mutual exclusion on a file using flock(2)
- Host: GitHub
- URL: https://github.com/rossmacarthur/fmutex
- Owner: rossmacarthur
- License: apache-2.0
- Created: 2022-02-09T10:27:40.000Z (about 3 years ago)
- Default Branch: trunk
- Last Pushed: 2022-02-09T10:28:04.000Z (about 3 years ago)
- Last Synced: 2024-12-23T21:11:50.069Z (about 2 months ago)
- Language: Rust
- Size: 9.77 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# fmutex
[](https://crates.io/crates/fmutex)
[](https://docs.rs/fmutex)Provides mutual exclusion on a file using
[`flock(2)`](https://man7.org/linux/man-pages/man2/flock.2.html).## Usage
### `lock()`
```rust
{
let _guard = fmutex::lock(path)?;// do mutually exclusive stuff here
} // <-- `_guard` dropped here and the lock is released
```### `try_lock()`
```rust
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](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)at your option.