scheduler: sched_terminateprogram()

This commit is contained in:
Matheus
2024-05-22 17:10:33 -03:00
parent a8970c4b27
commit 6bc3747856
4 changed files with 18 additions and 16 deletions
+1
View File
@@ -155,5 +155,6 @@ void sched_targetcpu(struct cpu_t *cpu);
void sched_sleepus(size_t us);
void sched_apentry();
void sched_inactiveproc(proc_t *proc);
void sched_terminateprogram(int status);
#endif
+13
View File
@@ -407,6 +407,19 @@ void sched_stopotherthreads() {
proc->nomorethreads = false;
}
void sched_terminateprogram(int status) {
thread_t *thread = _cpu()->thread;
proc_t *proc = thread->proc;
if (spinlock_try(&proc->exiting) == false)
sched_threadexit();
sched_stopotherthreads();
proc->status = status;
sched_threadexit();
}
static void yield(context_t *context) {
thread_t *thread = _cpu()->thread;
+2 -6
View File
@@ -253,12 +253,10 @@ bool signal_check(struct thread_t *thread, context_t *context, bool syscall, uin
THREAD_ENTER(thread);
if (SIGNAL_GET(&proc->signals.pending, SIGKILL) || SIGNAL_GET(&thread->signals.pending, SIGKILL)) {
// TODO terminate entire program
THREAD_LEAVE(thread);
PROCESS_LEAVE(proc);
proc->status = SIGKILL;
interrupt_set(true);
sched_threadexit();
sched_terminateprogram(SIGKILL);
}
// find the first pending signal which is unmasked
@@ -312,12 +310,10 @@ bool signal_check(struct thread_t *thread, context_t *context, bool syscall, uin
goto leave;
case ACTION_CORE:
case ACTION_TERM:
// TODO terminate entire program
proc->status = signal;
THREAD_LEAVE(thread);
PROCESS_LEAVE(proc);
interrupt_set(true);
sched_threadexit();
sched_terminateprogram(signal);
case ACTION_STOP:
// TODO what if a thread unmasks a stop signal?
// check if sigcont is not pending for the thread (SIGCONT is always sent to the thread)
+2 -10
View File
@@ -6,14 +6,6 @@
#include <semaphore.h>
__attribute__((noreturn)) void syscall_exit(context_t *context, int status) {
thread_t *thread = _cpu()->thread;
proc_t *proc = thread->proc;
if (spinlock_try(&proc->exiting) == false)
sched_threadexit();
sched_stopotherthreads();
proc->status = status << 8;
sched_threadexit();
sched_terminateprogram(status << 8);
__builtin_unreachable();
}