diff options
author | Dario Nieuwenhuis <dirbaio@dirbaio.net> | 2022-08-12 15:32:35 +0200 |
---|---|---|
committer | Dario Nieuwenhuis <dirbaio@dirbaio.net> | 2022-08-17 20:19:16 +0200 |
commit | beed7433fb8dd80e6a395034aa90613c5d6d74fd (patch) | |
tree | 4f0942c15e067920fd5d72ce07de157c7fc47c79 /nrf-softdevice/src/critical_section_impl.rs | |
parent | ab0ad770c729b4f034bf0a085b50347a3e6b2ea9 (diff) | |
download | nrf-softdevice-beed7433fb8dd80e6a395034aa90613c5d6d74fd.zip |
Add support for critical-section 1.0.
Diffstat (limited to 'nrf-softdevice/src/critical_section_impl.rs')
-rw-r--r-- | nrf-softdevice/src/critical_section_impl.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/nrf-softdevice/src/critical_section_impl.rs b/nrf-softdevice/src/critical_section_impl.rs index 59f9445..cb955fd 100644 --- a/nrf-softdevice/src/critical_section_impl.rs +++ b/nrf-softdevice/src/critical_section_impl.rs @@ -53,10 +53,11 @@ unsafe fn raw_critical_section<R>(f: impl FnOnce() -> R) -> R { } struct CriticalSection; -critical_section::custom_impl!(CriticalSection); +critical_section_1::set_impl!(CriticalSection); +critical_section_02::custom_impl!(CriticalSection); -unsafe impl critical_section::Impl for CriticalSection { - unsafe fn acquire() -> u8 { +unsafe impl critical_section_1::Impl for CriticalSection { + unsafe fn acquire() -> bool { let nvic = &*NVIC::PTR; let nested_cs = CS_FLAG.load(Ordering::SeqCst); @@ -74,14 +75,14 @@ unsafe impl critical_section::Impl for CriticalSection { compiler_fence(Ordering::SeqCst); - return nested_cs as u8; + nested_cs } - unsafe fn release(token: u8) { + unsafe fn release(nested_cs: bool) { compiler_fence(Ordering::SeqCst); let nvic = &*NVIC::PTR; - if token == 0 { + if !nested_cs { raw_critical_section(|| { CS_FLAG.store(false, Ordering::Relaxed); // restore only non-reserved irqs. @@ -90,3 +91,13 @@ unsafe impl critical_section::Impl for CriticalSection { } } } + +unsafe impl critical_section_02::Impl for CriticalSection { + unsafe fn acquire() -> u8 { + <Self as critical_section_1::Impl>::acquire() as _ + } + + unsafe fn release(token: u8) { + <Self as critical_section_1::Impl>::release(token != 0) + } +} |