mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-31 22:48:21 +00:00
scheduler: properly open init cwd and root, sched_dequeue()
This commit is contained in:
@@ -67,6 +67,8 @@ typedef struct{
|
|||||||
int lock;
|
int lock;
|
||||||
} sched_queue;
|
} sched_queue;
|
||||||
|
|
||||||
|
void sched_dequeue();
|
||||||
|
proc_t* sched_getinit();
|
||||||
thread_t* sched_newuthread(void* ip, size_t stacksize, void* stack, proc_t* proc, bool run, int prio);
|
thread_t* sched_newuthread(void* ip, size_t stacksize, void* stack, proc_t* proc, bool run, int prio);
|
||||||
thread_t* sched_newkthread(void* ip, size_t stacksize, bool run, int prio);
|
thread_t* sched_newkthread(void* ip, size_t stacksize, bool run, int prio);
|
||||||
void sched_queuethread(thread_t* thread);
|
void sched_queuethread(thread_t* thread);
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ sched_queue queues[QUEUE_COUNT];
|
|||||||
|
|
||||||
static int pidlock;
|
static int pidlock;
|
||||||
static pid_t nextpid = 1;
|
static pid_t nextpid = 1;
|
||||||
|
static proc_t* init;
|
||||||
|
|
||||||
|
proc_t* sched_getinit(){
|
||||||
|
return init;
|
||||||
|
}
|
||||||
|
|
||||||
static proc_t* allocproc(size_t threadcount){
|
static proc_t* allocproc(size_t threadcount){
|
||||||
|
|
||||||
@@ -234,7 +239,7 @@ void switch_thread(thread_t* thread){
|
|||||||
arch_setkernelstack(thread->kernelstack);
|
arch_setkernelstack(thread->kernelstack);
|
||||||
|
|
||||||
arch_regs_setupextra(&thread->extraregs);
|
arch_regs_setupextra(&thread->extraregs);
|
||||||
|
|
||||||
arch_switchcontext(thread->regs);
|
arch_switchcontext(thread->regs);
|
||||||
|
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
@@ -309,8 +314,6 @@ void sched_yieldtrampoline(thread_t* thread){
|
|||||||
|
|
||||||
|
|
||||||
thread_t* nthread = getnext();
|
thread_t* nthread = getnext();
|
||||||
|
|
||||||
nthread->state = THREAD_STATE_RUNNING;
|
|
||||||
|
|
||||||
timer_resume();
|
timer_resume();
|
||||||
|
|
||||||
@@ -348,6 +351,33 @@ void sched_eventsignal(event_t* event, thread_t* thread){
|
|||||||
spinlock_release(&queues[thread->priority].lock);
|
spinlock_release(&queues[thread->priority].lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sched_dequeue(){
|
||||||
|
|
||||||
|
timer_stop();
|
||||||
|
arch_interrupt_disable();
|
||||||
|
|
||||||
|
thread_t* thread = getnext();
|
||||||
|
|
||||||
|
timer_resume();
|
||||||
|
|
||||||
|
thread_t* curthread = arch_getcls()->thread;
|
||||||
|
|
||||||
|
// context and thread destruction will happen in the waitpid()
|
||||||
|
// the pointer to this thread will reside in proc->threads
|
||||||
|
|
||||||
|
curthread->proc->threads = curthread;
|
||||||
|
|
||||||
|
// for safety
|
||||||
|
|
||||||
|
|
||||||
|
arch_getcls()->thread = thread;
|
||||||
|
vmm_switchcontext(thread->ctx);
|
||||||
|
|
||||||
|
switch_thread(thread);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void sched_block(bool interruptible){
|
void sched_block(bool interruptible){
|
||||||
|
|
||||||
thread_t* thread = arch_getcls()->thread;
|
thread_t* thread = arch_getcls()->thread;
|
||||||
@@ -374,13 +404,14 @@ void sched_runinit(){
|
|||||||
thread_t* thread = sched_newuthread(NULL, PAGE_SIZE*10, NULL, NULL, false, THREAD_PRIORITY_USER);
|
thread_t* thread = sched_newuthread(NULL, PAGE_SIZE*10, NULL, NULL, false, THREAD_PRIORITY_USER);
|
||||||
|
|
||||||
proc_t* proc = thread->proc;
|
proc_t* proc = thread->proc;
|
||||||
|
init = proc;
|
||||||
|
|
||||||
arch_getcls()->thread = thread;
|
arch_getcls()->thread = thread;
|
||||||
|
|
||||||
vmm_switchcontext(thread->ctx);
|
vmm_switchcontext(thread->ctx);
|
||||||
|
|
||||||
proc->root = vfs_root();
|
vfs_open(&proc->root, vfs_root(), "/");
|
||||||
proc->cwd = vfs_root();
|
vfs_open(&proc->cwd, vfs_root(), "/");
|
||||||
|
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user