[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

@@ -5,6 +5,7 @@
#include "objects/process.h"
#include "objects/thread.h"
#include "objects/vm_area.h"
#include "scheduler.h"
// This object is initialized _before_ global constructors are called,
// so we don't want it to have a global constructor at all, lest it
@@ -62,6 +63,9 @@ process::exit(unsigned code)
}
m_return_code = code;
assert_signal(j6_signal_process_exit);
if (this == bsp_cpu_data.p)
scheduler::get().schedule();
}
void
@@ -90,6 +94,9 @@ process::update()
thread *
process::create_thread(uint8_t priority, bool user)
{
if (priority == default_pri)
priority = scheduler::default_priority;
thread *th = new thread(*this, priority);
kassert(th, "Failed to create thread!");
@@ -104,6 +111,7 @@ process::create_thread(uint8_t priority, bool user)
}
m_threads.append(th);
scheduler::get().add_thread(th->tcb());
return th;
}