[kernel] Add thead kobject class
Add the thread kernel API object and move the scheduler to use threads instead of processes for scheduling and task switching.
This commit is contained in:
@@ -10,16 +10,18 @@ j6_status_t
|
||||
process_exit(int64_t status)
|
||||
{
|
||||
auto &s = scheduler::get();
|
||||
auto *p = s.current();
|
||||
log::debug(logs::syscall, "Process %d exiting with code %d", p->pid, status);
|
||||
TCB *tcb = s.current();
|
||||
thread *th = tcb->thread_data;
|
||||
log::debug(logs::syscall, "Thread %llx exiting with code %d", th->koid(), status);
|
||||
|
||||
p->exit(status);
|
||||
th->exit(status);
|
||||
s.schedule();
|
||||
|
||||
log::error(logs::syscall, "returned to exit syscall");
|
||||
return j6_err_unexpected;
|
||||
}
|
||||
|
||||
/*
|
||||
j6_status_t
|
||||
process_fork(pid_t *pid)
|
||||
{
|
||||
@@ -54,6 +56,7 @@ process_getpid(pid_t *pid)
|
||||
*pid = p->pid;
|
||||
return j6_status_ok;
|
||||
}
|
||||
*/
|
||||
|
||||
j6_status_t
|
||||
process_log(const char *message)
|
||||
@@ -63,17 +66,22 @@ process_log(const char *message)
|
||||
}
|
||||
|
||||
auto &s = scheduler::get();
|
||||
auto *p = s.current();
|
||||
log::info(logs::syscall, "Message[%d]: %s", p->pid, message);
|
||||
TCB *tcb = s.current();
|
||||
thread *th = tcb->thread_data;
|
||||
log::info(logs::syscall, "Message[%llx]: %s", th->koid(), message);
|
||||
return j6_status_ok;
|
||||
}
|
||||
|
||||
j6_status_t process_fork(uint32_t *pid) { *pid = 5; return process_log("CALLED FORK"); }
|
||||
j6_status_t process_getpid(uint32_t *pid) { *pid = 0; return process_log("CALLED GETPID"); }
|
||||
|
||||
j6_status_t
|
||||
process_pause()
|
||||
{
|
||||
auto &s = scheduler::get();
|
||||
auto *p = s.current();
|
||||
p->wait_on_signal(-1ull);
|
||||
TCB *tcb = s.current();
|
||||
thread *th = tcb->thread_data;
|
||||
th->wait_on_signals(th, -1ull);
|
||||
s.schedule();
|
||||
return j6_status_ok;
|
||||
}
|
||||
@@ -82,10 +90,11 @@ j6_status_t
|
||||
process_sleep(uint64_t til)
|
||||
{
|
||||
auto &s = scheduler::get();
|
||||
auto *p = s.current();
|
||||
log::debug(logs::syscall, "Process %d sleeping until %llu", p->pid, til);
|
||||
TCB *tcb = s.current();
|
||||
thread *th = tcb->thread_data;
|
||||
log::debug(logs::syscall, "Thread %llx sleeping until %llu", th->koid(), til);
|
||||
|
||||
p->wait_on_time(til);
|
||||
th->wait_on_time(til);
|
||||
s.schedule();
|
||||
return j6_status_ok;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user