mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
xous-rs: cache the current process ID
This value does not change, so cache it in order to reduce the number of trips to the kernel. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
c96514d365
commit
c7c5a56a7d
1 changed files with 14 additions and 2 deletions
|
|
@ -1,9 +1,21 @@
|
||||||
|
use core::sync::atomic::{AtomicU32, Ordering};
|
||||||
|
|
||||||
|
static CACHED_PID: AtomicU32 = AtomicU32::new(0);
|
||||||
|
|
||||||
pub fn id() -> u32 {
|
pub fn id() -> u32 {
|
||||||
|
let pid = CACHED_PID.load(Ordering::Relaxed);
|
||||||
|
if pid != 0 {
|
||||||
|
return pid;
|
||||||
|
}
|
||||||
|
|
||||||
if let Ok(pid) = crate::syscall::current_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 {
|
} else {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_id(_id: u32) {}
|
pub fn set_id(id: u32) {
|
||||||
|
CACHED_PID.store(id, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue