mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[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:
@@ -4,7 +4,6 @@
|
||||
#include "log.h"
|
||||
#include "objects/process.h"
|
||||
#include "objects/thread.h"
|
||||
#include "scheduler.h"
|
||||
|
||||
namespace syscalls {
|
||||
|
||||
@@ -21,14 +20,14 @@ thread_koid(j6_koid_t *koid)
|
||||
j6_status_t
|
||||
thread_create(void *rip, j6_handle_t *handle)
|
||||
{
|
||||
scheduler &s = scheduler::get();
|
||||
thread &parent = thread::current();
|
||||
process &p = parent.parent();
|
||||
|
||||
thread *child = p.create_thread(scheduler::default_priority);
|
||||
thread *child = p.create_thread();
|
||||
child->add_thunk_user(reinterpret_cast<uintptr_t>(rip));
|
||||
*handle = p.add_handle(child);
|
||||
s.add_thread(child->tcb());
|
||||
child->clear_state(thread::state::loading);
|
||||
child->set_state(thread::state::ready);
|
||||
|
||||
log::debug(logs::syscall, "Thread %llx spawned new thread %llx, handle %d",
|
||||
parent.koid(), child->koid(), *handle);
|
||||
@@ -39,11 +38,9 @@ thread_create(void *rip, j6_handle_t *handle)
|
||||
j6_status_t
|
||||
thread_exit(int64_t status)
|
||||
{
|
||||
auto &s = scheduler::get();
|
||||
thread &th = thread::current();
|
||||
log::debug(logs::syscall, "Thread %llx exiting with code %d", th.koid(), status);
|
||||
th.exit(status);
|
||||
s.schedule();
|
||||
|
||||
log::error(logs::syscall, "returned to exit syscall");
|
||||
return j6_err_unexpected;
|
||||
@@ -52,22 +49,18 @@ thread_exit(int64_t status)
|
||||
j6_status_t
|
||||
thread_pause()
|
||||
{
|
||||
auto &s = scheduler::get();
|
||||
thread &th = thread::current();
|
||||
th.wait_on_signals(&th, -1ull);
|
||||
s.schedule();
|
||||
return j6_status_ok;
|
||||
}
|
||||
|
||||
j6_status_t
|
||||
thread_sleep(uint64_t til)
|
||||
{
|
||||
auto &s = scheduler::get();
|
||||
thread &th = thread::current();
|
||||
log::debug(logs::syscall, "Thread %llx sleeping until %llu", th.koid(), til);
|
||||
|
||||
th.wait_on_time(til);
|
||||
s.schedule();
|
||||
return j6_status_ok;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user