diff --git a/xous-rs/src/process.rs b/xous-rs/src/process.rs index a7bde40d1..ac6cc8ad8 100644 --- a/xous-rs/src/process.rs +++ b/xous-rs/src/process.rs @@ -1,9 +1,21 @@ +use core::sync::atomic::{AtomicU32, Ordering}; + +static CACHED_PID: AtomicU32 = AtomicU32::new(0); + pub fn id() -> u32 { + let pid = CACHED_PID.load(Ordering::Relaxed); + if pid != 0 { + return pid; + } + if let Ok(pid) = crate::syscall::current_pid() { - pid.get() as u32 + CACHED_PID.store(pid.get() as u32, Ordering::Relaxed); + pid.get() as u32; } else { 0 } } -pub fn set_id(_id: u32) {} +pub fn set_id(id: u32) { + CACHED_PID.store(id, Ordering::Relaxed); +}