Skip to content

Commit f17d22a

Browse files
authored
Microoptimizations around panics
Merges: #82
2 parents e53ed13 + f228192 commit f17d22a

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

src/panic.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
fn panic(info: &::core::panic::PanicInfo) -> ! {
33
use crate::thread;
44

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

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

52-
if cfg!(feature = "panic_handler_crash") {
53-
unsafe {
54-
riot_sys::core_panic(
55-
riot_sys::core_panic_t_PANIC_GENERAL_ERROR,
56-
cstr::cstr!("RUST PANIC").as_ptr() as _,
57-
)
58-
}
59-
}
60-
6153
// Not trying any unwinding -- this thread is just dead, won't be re-claimed, any mutexes it
6254
// holds are just held indefinitely rather than throwing poison errors.
6355
loop {

src/thread/riot_c.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ impl KernelPID {
106106
}
107107

108108
pub fn get_name(&self) -> Option<&str> {
109+
// Shortcut through an otherwise unoptimizable function
110+
if !cfg!(riot_develhelp) {
111+
return None;
112+
}
113+
109114
let ptr = unsafe { raw::thread_getname(self.0) };
110115

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

0 commit comments

Comments
 (0)