Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lukaskalbertodt/atomig
Generic and convenient `std` atomics via `Atomic<T>`
https://github.com/lukaskalbertodt/atomig
atomics cas generic rust
Last synced: 4 days ago
JSON representation
Generic and convenient `std` atomics via `Atomic<T>`
- Host: GitHub
- URL: https://github.com/lukaskalbertodt/atomig
- Owner: LukasKalbertodt
- License: apache-2.0
- Created: 2019-07-20T10:30:07.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-03-04T21:44:29.000Z (8 months ago)
- Last Synced: 2024-08-09T05:12:00.241Z (3 months ago)
- Topics: atomics, cas, generic, rust
- Language: Rust
- Homepage: https://docs.rs/atomig
- Size: 157 KB
- Stars: 36
- Watchers: 4
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
Atomig: generic and convenient `std` atomics
============================================[](https://github.com/LukasKalbertodt/atomig/actions/workflows/ci.yml)
[](https://crates.io/crates/atomig)
[](https://docs.rs/atomig)Offers `Atomic` that can be used with primitive and custom types.
*However*, it only works with types that can actually use atomic operations: a lock-based fallback for other types is not used!
This crate is based on `std`'s atomics and therefore does not contain any `unsafe` code!
This crate also does not have any dependencies by default.
If you enable the `serde` feature, then this crate will depend on `serde` and `Serialize` / `Deserialize` will be
implemented for `Atomic` when appropriate, using sequentially-consistent ordering.Simple example with primitive types:
```rust
use atomig::{Atomic, Ordering};let x = Atomic::new(27); // `Atomic`
x.store(39, Ordering::SeqCst);
```This works with almost all primitive types, including `f32`, `f64` and `char`,
but also with types like `std::ptr::NonNull` and `std::num::NonZero`.You can automatically derive `Atom` for your own enum or struct types to use them in `Atomic`.
There are some limitations, however.```rust
// Requires the 'derive' feature:
// atomig = { version = "_", features = ["derive"] }
use atomig::{Atom, Atomic, Ordering};#[derive(Atom)]
#[repr(u8)]
enum Animal { Dog, Cat, Fox }let animal = Atomic::new(Animal::Cat);
animal.store(Animal::Fox, Ordering::SeqCst);#[derive(Atom)]
struct Port(u16);let port = Atomic::new(Port(80));
port.store(Port(8080), Ordering::SeqCst);
```For more examples and information see **[the documentation](https://docs.rs/atomig)**.
---
## License
Licensed under either of Apache License, Version
2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this project by you, as defined in the Apache-2.0 license,
shall be dual licensed as above, without any additional terms or conditions.