mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
kernel: services: fix sending messages within a process
This fixes the case where there is only one process active and it tries to send messages to itself, or it yields to itself. This closes issue #42. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
cc4c0f3c58
commit
db8e814cb7
1 changed files with 40 additions and 37 deletions
|
|
@ -942,50 +942,53 @@ impl SystemServices {
|
||||||
// previous_pid, previous.state, can_resume
|
// previous_pid, previous.state, can_resume
|
||||||
// );
|
// );
|
||||||
} else {
|
} else {
|
||||||
// if self.current_thread(previous_pid) == new_tid {
|
let new = self.get_process_mut(new_pid)?;
|
||||||
// if !can_resume {
|
|
||||||
// panic!("tried to switch to our own context without resume");
|
|
||||||
// }
|
|
||||||
// return Ok(new_tid);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// we can get here if we're activating a new thread in the same process
|
// If we wanted to switch to a "new" thread, and it's the same
|
||||||
//return Ok(new_tid);
|
// as the one we just switched from, do nothing.
|
||||||
|
if new.current_thread == new_tid {
|
||||||
|
if !can_resume {
|
||||||
|
panic!("tried to switch to our own context without resume");
|
||||||
|
}
|
||||||
|
return Ok(new_tid);
|
||||||
|
}
|
||||||
|
|
||||||
let new = self.get_process_mut(new_pid)?; /*
|
// Transition to the new state.
|
||||||
new.state = match new.state {
|
new.state = if let ProcessState::Running(x) = new.state {
|
||||||
ProcessState::Running(x) if (x & 1 << new_tid) == 0 => {
|
let previous_tid = new.current_thread;
|
||||||
return Err(xous_kernel::Error::ProcessNotFound)
|
// If no new thread is specified, take the previous
|
||||||
}
|
// thread. If that is not runnable, do a round-robin
|
||||||
// ProcessState::Running(x) => {
|
// search for the next available thread.
|
||||||
// if can_resume {
|
if new_tid == 0 {
|
||||||
// ProcessState::Running((x | (1 << previous_tid)) & !(1 << new_tid))
|
new_tid = (new.current_thread + 1) as usize;
|
||||||
// } else {
|
while x & (1 << new_tid) == 0 {
|
||||||
// ProcessState::Running(x | (1 << previous_tid))
|
new_tid += 1;
|
||||||
// }
|
if new_tid > arch::process::MAX_THREAD {
|
||||||
// }
|
new_tid = 0;
|
||||||
other => */
|
} else if new_tid == (new.current_thread + 1) as usize {
|
||||||
panic!(
|
// If we've looped around, return an error.
|
||||||
"PID {} invalid process state (not Running): {:?}",
|
return Err(xous_kernel::Error::ProcessNotFound);
|
||||||
previous_pid, new.state
|
}
|
||||||
) /*,
|
}
|
||||||
}*/
|
new.current_thread = new_tid as _;
|
||||||
;
|
} else if x & (1 << new_tid) == 0 {
|
||||||
// if advance_thread {
|
return Err(xous_kernel::Error::ProcessNotFound);
|
||||||
// new.current_thread += 1;
|
}
|
||||||
// if new.current_thread as TID > arch::process::MAX_CONTEXT {
|
// Mark the previous TID as being runnable, and remove the new TID
|
||||||
// new.current_thread = 0;
|
// from the list of threads that can be run.
|
||||||
// }
|
ProcessState::Running(x & !(1 << new_tid) | if can_resume { 1 << previous_tid } else { 0 })
|
||||||
// }
|
} else {
|
||||||
|
panic!(
|
||||||
|
"PID {} invalid process state (not Running): {:?}",
|
||||||
|
previous_pid, new.state
|
||||||
|
)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
// self.pid = new_pid;
|
|
||||||
|
|
||||||
let mut process = crate::arch::process::Process::current();
|
let mut process = crate::arch::process::Process::current();
|
||||||
|
|
||||||
// Restore the previous context, if one exists.
|
// Restore the previous thread, if one exists.
|
||||||
process.set_thread(new_tid)?;
|
process.set_thread(new_tid)?;
|
||||||
// self.processes[new_pid.get() as usize - 1].current_thread = new_tid as u8;
|
|
||||||
// let _ctx = process.current_context();
|
|
||||||
|
|
||||||
Ok(new_tid)
|
Ok(new_tid)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue