-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
portable_atomic
for atomics support
- Loading branch information
Joel Aschmann
committed
Mar 24, 2023
1 parent
3b057d3
commit c7df4f1
Showing
4 changed files
with
45 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//! [`critical_section`] implementation for **single core cpu boards** | ||
//! using RIOTs interrupts interface. (Just disables interrupts). | ||
//! | ||
//! This is needed by [`portable_atomic`] to provide atomics to boards without hardware | ||
//! support or rather where rust does not support atomics. | ||
use critical_section::RawRestoreState; | ||
|
||
struct RIOTCriticalSection; | ||
|
||
critical_section::set_impl!(RIOTCriticalSection); | ||
|
||
unsafe impl critical_section::Impl for RIOTCriticalSection { | ||
unsafe fn acquire() -> RawRestoreState { | ||
if crate::irq_is_in() { | ||
return false; | ||
} | ||
|
||
let disabled = crate::irq_is_enabled(); | ||
// It is possible that between here an interrupt | ||
// interferes and causes another thread/process to continue. | ||
// This should not be a problem because: | ||
// Szenario 1: The other process does not enter a critical section | ||
// or disables interrupts and nothing happens. | ||
// Szenario 2: The other process does disable interrupts, but | ||
// then this thread here can only continue once the interrupts are back on | ||
// and one causes this thread to continue. | ||
// In both cases we should not face a toctu problem. | ||
crate::irq_disable(); | ||
disabled | ||
} | ||
|
||
unsafe fn release(token: RawRestoreState) { | ||
if token { | ||
crate::irq_enable(); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -110,6 +110,8 @@ pub mod libc; | |
|
||
mod intrinsics_replacements; | ||
|
||
mod critical_section; | ||
|
||
mod bindgen; | ||
pub mod inline; | ||
|
||
|