Skip to content

Commit

Permalink
Microoptimizations around panics
Browse files Browse the repository at this point in the history
Merges: #82
  • Loading branch information
chrysn authored Mar 20, 2024
2 parents e53ed13 + f228192 commit f17d22a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
fn panic(info: &::core::panic::PanicInfo) -> ! {
use crate::thread;

let os_can_continue = crate::thread::InThread::new()
// Panics with IRQs off are fatal because we can't safely re-enable them
.map(|i| i.irq_is_enabled())
// Panics in ISRs are always fatal because continuing in threads would signal to the
// remaining system that the ISR terminated
.unwrap_or(false);
let os_can_continue = !cfg!(feature = "panic_handler_crash")
&& crate::thread::InThread::new()
// Panics with IRQs off are fatal because we can't safely re-enable them
.map(|i| i.irq_is_enabled())
// Panics in ISRs are always fatal because continuing in threads would signal to the
// remaining system that the ISR terminated
.unwrap_or(false);

if !os_can_continue {
// We can't abort on stable -- but even if we could: Set a breakpoint and wait for the
Expand Down Expand Up @@ -49,15 +50,6 @@ fn panic(info: &::core::panic::PanicInfo) -> ! {
let _ = stdio.write_str("!\n");
}

if cfg!(feature = "panic_handler_crash") {
unsafe {
riot_sys::core_panic(
riot_sys::core_panic_t_PANIC_GENERAL_ERROR,
cstr::cstr!("RUST PANIC").as_ptr() as _,
)
}
}

// Not trying any unwinding -- this thread is just dead, won't be re-claimed, any mutexes it
// holds are just held indefinitely rather than throwing poison errors.
loop {
Expand Down
5 changes: 5 additions & 0 deletions src/thread/riot_c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ impl KernelPID {
}

pub fn get_name(&self) -> Option<&str> {
// Shortcut through an otherwise unoptimizable function
if !cfg!(riot_develhelp) {
return None;
}

let ptr = unsafe { raw::thread_getname(self.0) };

// If the thread stops, the name might be not valid any more, but then again the getname
Expand Down

0 comments on commit f17d22a

Please sign in to comment.