feature: spawn for closures

This commit is contained in:
2021-11-19 16:14:13 +02:00
parent adb95ac52e
commit d582a9b58b
8 changed files with 171 additions and 44 deletions
+32
View File
@@ -234,6 +234,38 @@ impl Process {
panic!("This code should never run");
}
pub fn exit_thread(thread: ThreadRef) {
let switch = {
let switch = thread.state() == ThreadState::Running;
let process = thread.owner().unwrap();
let mut lock = process.inner.lock();
let tid = thread.id();
if lock.threads.len() == 1 {
// TODO call Process::exit instead?
todo!();
}
lock.threads.retain(|&e| e != tid);
thread.terminate();
SCHED.dequeue(tid);
debugln!("Thread {} terminated", tid);
switch
};
if switch {
// TODO retain thread ID in process "finished" list and
// drop it when process finishes
SCHED.switch(true);
panic!("This code should not run");
} else {
// Can drop this thread: it's not running
todo!();
}
}
fn collect(&self) -> Option<ExitCode> {
let lock = self.inner.lock();
if lock.state == ProcessState::Finished {
+4
View File
@@ -58,6 +58,10 @@ pub fn syscall(num: usize, args: &[usize]) -> Result<usize, Errno> {
Process::exit(args[0] as i32);
unreachable!();
}
abi::SYS_EX_THREAD_EXIT => {
Process::exit_thread(Thread::current());
unreachable!();
},
// I/O system calls
abi::SYS_OPENAT => {