mvdnes / spin-rs

Spin-based synchronization primitives
MIT License
485 stars 92 forks source link

Add portable_atomic feature #120

Closed fralalonde closed 2 years ago

fralalonde commented 2 years ago

Add optional portable_atomic feature to enable the portable-atomic crate for use of emulated atomic operations on platforms that don't have them.

This is in response to https://github.com/mvdnes/spin-rs/issues/114. Code changes follow closely those of previously proposed atomic-polyfill PR https://github.com/mvdnes/spin-rs/pull/115

I've expanded a bit on the feature and its implications in the README.

Tested as working with my app (unpublished yet) - a host USB stack on Atmel SAM D21 which has a single Cortex-M0 core.

I will gladly update this PR if any changes are deemed necessary.

zesterer commented 2 years ago

Thanks for the PR! This broadly looks fine to me. Just to check: are you 100% sure that you caught all existing uses of core::sync::atomic?

fralalonde commented 2 years ago

The requested changes make sense and have been applied.

I've reviewed references to core::sync::atomic and the only occurrence is the one that is under the #[cfg(not(feature = "portable_atomic"))] condition. References to std::sync::atomic are confined to tests and unaffected.

zesterer commented 2 years ago

Thanks for making those changes. Are you in need of this feature soon, or are you happy to wait for the next stable release?

fralalonde commented 2 years ago

Thanks!

I have no problem sticking to my branch until the next release.