mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-28 04:40:52 +00:00
Put the whole print macro in a critical section (#4154)
This commit is contained in:
parent
62529e2fd3
commit
9f7193fec4
@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Fixed
|
||||
|
||||
- `critical-section` now wraps the entirety of the `print!` macros (#4154)
|
||||
|
||||
### Removed
|
||||
|
||||
|
@ -40,8 +40,10 @@ log_format!("serial");
|
||||
macro_rules! println {
|
||||
($($arg:tt)*) => {{
|
||||
{
|
||||
use core::fmt::Write;
|
||||
writeln!($crate::Printer, $($arg)*).ok();
|
||||
$crate::with(|_| {
|
||||
use core::fmt::Write;
|
||||
writeln!($crate::Printer, $($arg)*).ok();
|
||||
});
|
||||
}
|
||||
}};
|
||||
}
|
||||
@ -52,8 +54,10 @@ macro_rules! println {
|
||||
macro_rules! print {
|
||||
($($arg:tt)*) => {{
|
||||
{
|
||||
use core::fmt::Write;
|
||||
write!($crate::Printer, $($arg)*).ok();
|
||||
$crate::with(|_| {
|
||||
use core::fmt::Write;
|
||||
write!($crate::Printer, $($arg)*).ok();
|
||||
});
|
||||
}
|
||||
}};
|
||||
}
|
||||
@ -486,7 +490,8 @@ mod noop {
|
||||
use core::marker::PhantomData;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct LockToken<'a>(PhantomData<&'a ()>);
|
||||
#[doc(hidden)]
|
||||
pub struct LockToken<'a>(PhantomData<&'a ()>);
|
||||
|
||||
impl LockToken<'_> {
|
||||
#[allow(unused)]
|
||||
@ -499,8 +504,9 @@ impl LockToken<'_> {
|
||||
static LOCK: esp_sync::RawMutex = esp_sync::RawMutex::new();
|
||||
|
||||
/// Runs the callback in a critical section, if enabled.
|
||||
#[doc(hidden)]
|
||||
#[inline]
|
||||
fn with<R>(f: impl FnOnce(LockToken) -> R) -> R {
|
||||
pub fn with<R>(f: impl FnOnce(LockToken) -> R) -> R {
|
||||
#[cfg(feature = "critical-section")]
|
||||
return LOCK.lock(|| f(unsafe { LockToken::conjure() }));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user