Skip to content
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

Non atomic RTT #699

Closed
wants to merge 5 commits into from
Closed

Non atomic RTT #699

wants to merge 5 commits into from

Conversation

Urhengulas
Copy link
Member

This PR replaces all atomic variables with their non-atomic counterpart wrapped in a critical_section::Mutex<RefCell<_>>. The RefCell is needed, because critical_section::Mutex does not provide interior mutability.

This change makes defmt-rtt available on targets without native atomics.
Fixes #597.

Atm, it is unclear what the runtime and code-size impact of that change is. Likely both would improve if using a Cell, instead of a RefCell, but it is unclear if that would be correct.

@Urhengulas
Copy link
Member Author

While it seems to work to replace AtomicT with critical_section::Mutex<Cell<T>>, we are not confident that there are no failure cases left that we didn't think about.

@Urhengulas Urhengulas closed this Oct 4, 2022
@@ -13,13 +10,13 @@ pub(crate) struct Channel {
pub buffer: *mut u8,
pub size: usize,
/// Written by the target.
pub write: AtomicUsize,
pub write: critical_section::Mutex<RefCell<usize>>,
Copy link

@TheButlah TheButlah Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a benefit to the mutex approach instead of using the atomic-polyfill crate from embassy?
If I understand correctly, that crate will use the native atomics when available, and polyfill atomics using critical-section when native ones aren't available

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might indeed be the better option.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #702

@Urhengulas Urhengulas deleted the non-atomic-rtt branch October 5, 2022 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for targets without native atomics
2 participants