-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use portable-atomic
instead of atomic-polyfill
.
#328
Conversation
39bf5cc
to
1001759
Compare
Hi please rebase to fix tsan failure |
1001759
to
9f0d39d
Compare
Hi, I gave this a check and saw something weird.
Is there a reason this is not a feature to |
it's a feature for |
Hmm, I see - that was one long discussion. 😅 Not sure what I think of it yet, I'll leave this open until I can come to terms with |
e3ac654
to
13a9d1a
Compare
Pushed new version:
With the current implementation, for targets without native CAS, the end-user will have to add a dep on |
//! # Portability | ||
//! | ||
//! This module requires CAS atomic instructions which are not available on all architectures | ||
//! (e.g. ARMv6-M (`thumbv6m-none-eabi`) and MSP430 (`msp430-none-elf`)). These atomics can be | ||
//! emulated however with [`portable-atomic`](https://crates.io/crates/portable-atomic), which is | ||
//! enabled with the `cas` feature and is enabled by default for `thumbv6m-none-eabi` and `riscv32` | ||
//! targets. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that this SPSC implementation does not require atomic CAS and only uses atomic load/store.
(FWIW, portable-atomic provides multicore-safe atomic load/store for riscv without A extension, even without critical-section feature or unsafe single-core cfg)
|
||
[target.'cfg(target_arch = "avr")'.dependencies] | ||
atomic-polyfill = { version = "1.0.1", optional = true } | ||
portable-atomic = { version = "1.0", optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this time, a builtin AVR target (avr-unknown-gnu-atmega328) does not provide atomic, and AVR targets used in avr-hal do not provide atomic load-store of pointer width. So I guess spsc which uses AtomicUsize will always require portable-atomic.
However, LLVM can provide 16-bit atomic load/store for AVR, so there is no need to necessarily remove optional=true here. (I should send a patch to rustc/avr-hal to update the target specs. EDIT: opened rust-lang/rust#114495)
When using the In any case, I hope examples I just added clarifies the step to use them... (Regarding whether to use cfg or feature, I'm considering adding a comment something like "If you feel that using the single-core cfg is annoying, consider using the |
@taiki-e: There's many cases where a crate knows it's going to run in single-core (for example Asking the user to add nonstandard Could you please consider adding a |
After discussion in tokio-rs/bytes#573, I'm starting to think that adding per-target/implementation The cross-platform However, I think per-target/implementation Footnotes
|
ping @korken89
|
c97a74e
to
8f6dc81
Compare
I intend to deprecate
atomic-polyfill
soon, in favor ofportable-atomic
. It supports more archs and is more actively maintained.The only thing it can't do yet is useit already can: taiki-e/portable-atomic#51critical-section
, but it should soon