forked from future-proof-iot/RIOT-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
104 additions
and
81 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,39 @@ | ||
//! This module provides a Mutex-protected RefCell --- basically a way to ensure | ||
//! at runtime that some reference is used only once. | ||
use core::cell::UnsafeCell; | ||
|
||
use critical_section::CriticalSection; | ||
|
||
use crate::critical_section; | ||
|
||
pub(crate) struct SchedulerLock<T> { | ||
inner: T, | ||
inner: UnsafeCell<T>, | ||
} | ||
|
||
impl<T> SchedulerLock<T> { | ||
pub const fn new(inner: T) -> Self { | ||
Self { inner } | ||
Self { | ||
inner: UnsafeCell::new(inner), | ||
} | ||
} | ||
|
||
pub fn with<F, R>(&self, f: F) -> R | ||
where | ||
F: FnOnce(&T) -> R, | ||
F: FnOnce(&mut T) -> R, | ||
{ | ||
critical_section::no_preemption_with(|| f(&self.inner)) | ||
critical_section::no_preemption_with(|| { | ||
let inner = unsafe { &mut *self.inner.get() }; | ||
f(inner) | ||
}) | ||
} | ||
|
||
pub fn with_cs<F, R>(&self, _cs: CriticalSection, f: F) -> R | ||
where | ||
F: FnOnce(&T) -> R, | ||
F: FnOnce(&mut T) -> R, | ||
{ | ||
f(&self.inner) | ||
let inner = unsafe { &mut *self.inner.get() }; | ||
f(inner) | ||
} | ||
} | ||
|
||
unsafe impl<T> Sync for SchedulerLock<T> {} |
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
Oops, something went wrong.