[kernel] Have thread call scheduler on blocking

Instead of making every callsite that may make a thread do a blocking
operation also invoke the scheduler, move that logic into thread
implementation - if the thread is blocking and is the current thread,
call schedule().

Related changes in this commit:

- Also make exiting threads and processes call the scheduler when
  blocking.
- Threads start blocked, and get automatically added to the scheduler's
  blocked list.
This commit is contained in:
2020-09-27 21:35:15 -07:00
parent ff78c951f0
commit 87b0a93d32
9 changed files with 35 additions and 38 deletions

View File

@@ -141,13 +141,14 @@ scheduler::create_process(bool user)
{
process *p = new process;
thread *th = p->create_thread(default_priority, user);
auto *tcb = th->tcb();
auto *tcb = th->tcb();
tcb->time_left = quantum(default_priority);
log::debug(logs::task, "Creating thread %llx, priority %d, time slice %d",
th->koid(), tcb->priority, tcb->time_left);
th->set_state(thread::state::ready);
return th;
}
@@ -183,8 +184,6 @@ scheduler::load_process(const char *name, const void *data, size_t size)
tcb->rsp3 = process::stacks_top;
m_runlists[default_priority].push_back(tcb);
log::debug(logs::task, "Loading thread %s: koid %llx pri %d", name, th->koid(), tcb->priority);
log::debug(logs::task, " RSP %016lx", tcb->rsp);
log::debug(logs::task, " RSP0 %016lx", tcb->rsp0);
@@ -203,7 +202,7 @@ scheduler::create_kernel_task(void (*task)(), uint8_t priority, bool constant)
if (constant)
th->set_state(thread::state::constant);
m_runlists[priority].push_back(tcb);
th->set_state(thread::state::ready);
log::debug(logs::task, "Creating kernel task: thread %llx pri %d", th->koid(), tcb->priority);
log::debug(logs::task, " RSP0 %016lx", tcb->rsp0);
@@ -247,7 +246,6 @@ void scheduler::prune(uint64_t now)
if (!exited && !ready)
continue;
if (exited) {
// If the current thread has exited, wait until the next call
// to prune() to delete it, because we may be deleting our current