atomic-shim
Atomic types shims for unsupported architectures.
This crate provides shims for std::sync::AtomicU64 and std::sync::AtomicI64 for mips and powerpc.
The std primitives are not available on all platforms, and that makes it tricky to write code for mips, such as OpenWRT Routers.
This crate provides it's own AtomicU64 and AtomicI64, which can directly replace the std::sync structs.
The crate does target detection and on supported architectures it will use std::sync structures.
When it detects it is running on unsupported platforms, it fallbacks to the shim implementation, using crossbeam Mutex.
For testing purposes, and for other reasons, you can replace the default implementation with the Mutex implementation by using the features = ["mutex"]
Usage
Replace any imports of use std::sync::AtomicU64; with use atomic_shim::Atomic64;
Installation
Add the dependency to your Cargo.toml, and optionally, exposes the mutex feature to test without cross-compiling:
[]
= "*"
# Optional
#[features]
#mutex = ["atomic-shim/mutex"]
Test
To run tests, it is important to enable the --features mutex.
Examples
A simple spinlock:
use Arc;
use Ordering;
use thread;
use AtomicU64;
Keep a global count of live threads:
use Ordering;
use AtomicU64;
let global_thread_count = new;
let old_thread_count = global_thread_count.fetch_add;
println!;
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.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.