feat(adapter-riscv): IPC demo — two processes exchange a message on QEMU virt
This commit is contained in:
@@ -113,6 +113,44 @@ impl<P: Platform> Kernel<P> {
|
||||
self.processes.get(pid).is_ok()
|
||||
}
|
||||
|
||||
pub fn create_endpoint(&mut self) -> Result<types::id::EndpointId, KernelError> {
|
||||
self.endpoints.create().ok_or(KernelError::NoFreeSlot)
|
||||
}
|
||||
|
||||
pub fn grant_capability(
|
||||
&mut self,
|
||||
to: ProcessId,
|
||||
resource: Resource,
|
||||
permissions: PermissionSet,
|
||||
) -> Result<CapSlot, KernelError> {
|
||||
self.grant_cap(to, resource, permissions)
|
||||
}
|
||||
|
||||
pub fn switch_to_thread(&mut self, tid: ThreadId) {
|
||||
use domain::scheduler::Scheduler;
|
||||
let core = self.platform.core_id();
|
||||
|
||||
if let Some(current) = self.scheduler.current(core) {
|
||||
if current == tid {
|
||||
return;
|
||||
}
|
||||
if let Ok(t) = self.threads.get_mut(current) {
|
||||
if matches!(t.state(), ThreadState::Running(_)) {
|
||||
let priority = t.priority();
|
||||
let _ = t.preempt();
|
||||
self.scheduler.add(current, priority, core);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(t) = self.threads.get(tid) {
|
||||
if matches!(t.state(), ThreadState::Ready) {
|
||||
self.scheduler.next(core);
|
||||
let _ = self.threads.get_mut(tid).map(|t| t.set_running(core));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn caller(&self) -> Result<(ThreadId, ProcessId), KernelError> {
|
||||
let core = self.platform.core_id();
|
||||
let tid = self.scheduler.current(core)
|
||||
|
||||
Reference in New Issue
Block a user