-
Notifications
You must be signed in to change notification settings - Fork 186
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,13 @@ | |
//! | ||
//! Implementation based on <https://www.codeproject.com/Articles/43510/Lock-Free-Single-Producer-Single-Consumer-Circular> | ||
//! | ||
//! NOTE: This module is not available on targets that do *not* support atomic loads and are not | ||
//! supported by [`atomic_polyfill`](https://crates.io/crates/atomic-polyfill). (e.g., MSP430). | ||
//! # 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. | ||
Comment on lines
+5
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
//! | ||
//! # Examples | ||
//! | ||
|
@@ -91,10 +96,12 @@ | |
|
||
use core::{cell::UnsafeCell, fmt, hash, mem::MaybeUninit, ptr}; | ||
|
||
#[cfg(full_atomic_polyfill)] | ||
use atomic_polyfill::{AtomicUsize, Ordering}; | ||
#[cfg(not(full_atomic_polyfill))] | ||
use core::sync::atomic::{AtomicUsize, Ordering}; | ||
#[cfg(not(use_portable_atomic))] | ||
use core::sync::atomic; | ||
#[cfg(use_portable_atomic)] | ||
use portable_atomic as atomic; | ||
|
||
use atomic::{AtomicUsize, Ordering}; | ||
|
||
/// A statically allocated single producer single consumer queue with a capacity of `N - 1` elements | ||
/// | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)