#atomic #polyfill

no-std atomic-polyfill

Atomic polyfills, for targets where they’re not available

6 releases

0.1.5 Nov 2, 2021
0.1.4 Sep 24, 2021
0.1.3 Aug 7, 2021
0.1.2 Mar 28, 2021

#81 in Embedded development

Download history 10135/week @ 2021-09-27 9967/week @ 2021-10-04 11510/week @ 2021-10-11 18597/week @ 2021-10-18 20469/week @ 2021-10-25 14331/week @ 2021-11-01 14232/week @ 2021-11-08 14824/week @ 2021-11-15 13995/week @ 2021-11-22 11633/week @ 2021-11-29 13970/week @ 2021-12-06 15712/week @ 2021-12-13 12347/week @ 2021-12-20 5719/week @ 2021-12-27 17081/week @ 2022-01-03 15690/week @ 2022-01-10

51,810 downloads per month
Used in 5 crates (4 directly)

MIT/Apache

21KB
502 lines

atomic-polyfill

Documentation

This crate polyfills atomics on targets where they're not available, using critical sections. It is intended to be a drop-in replacement for core::sync::atomic.

There is three "levels" of polyfilling:

  • Native: No polyfilling is performed, the native core::sync::atomic::AtomicXX is reexported.
  • CAS: Only compare-and-set operations are polyfilled, while loads and stores are native.
  • Full: Both load/store and compare-and-set operations are polyfilled.

Target support

The right polyfill level is automatically picked based on the target and the atomic width:

Target Level Level for u64/i64
thumbv6m CAS Full
thumbv7*, thumbv8* Native Full
riscv32imc Full1 Full
riscv32imac Native Full
Other2 Native Native

1: The hardware is capable of supporting atomic load/stores up to 32 bits, so this could be "CAS" instead of "Full". However, support for this is missing in Rust. See discussion here.

2: atomic-polyfill assumes unknown targets have full native support. This may not be true, in which case the build may fail. PRs for polyfilling more targets are welcome :)

Note: polyfill is based on critical sections using the critical-section crate. The default implementation is based on disabling all interrupts, so it's unsound on multi-core targets. It is possible to supply a custom critical section implementation, check the critical-section docs for details.

License

This work is licensed under either of

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.

Dependencies

~240KB