From c7c2e36c2bb2cf7302f60a70e0ede0490f98b05e Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Tue, 10 Aug 2010 21:38:26 +0200 Subject: No more global list of threads, one list of threads per process. --- Grapes.fl.img | Bin 1474560 -> 1474560 bytes src/kernel/task/sched.c | 2 ++ src/kernel/task/task.c | 37 +++++++++++++++++-------------------- src/kernel/task/task.h | 3 ++- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Grapes.fl.img b/Grapes.fl.img index 1f87dcc..2166fa4 100644 Binary files a/Grapes.fl.img and b/Grapes.fl.img differ diff --git a/src/kernel/task/sched.c b/src/kernel/task/sched.c index d2a4c5b..85329ea 100644 --- a/src/kernel/task/sched.c +++ b/src/kernel/task/sched.c @@ -4,6 +4,7 @@ static struct thread *queue = 0, *last = 0; +/* Used by task.c. Enqueus a thread in the queue of threads waiting to run. */ void sched_enqueue(struct thread *t) { t->queue_next = 0; if (queue == 0) { @@ -14,6 +15,7 @@ void sched_enqueue(struct thread *t) { } } +/* Used by task.c. Pops a thread from the queue to be run. */ struct thread *sched_dequeue() { if (queue == 0) return 0; struct thread *it = queue; diff --git a/src/kernel/task/task.c b/src/kernel/task/task.c index ccc7cc1..9d64b9e 100644 --- a/src/kernel/task/task.c +++ b/src/kernel/task/task.c @@ -24,7 +24,7 @@ extern void task_idle(void*); static uint32_t nextpid = 1; struct process *processes = 0, *kernel_process; -struct thread *threads = 0, *current_thread = 0, *idle_thread; +struct thread *current_thread = 0, *idle_thread; uint32_t tasking_tmpStack[KSTACKSIZE]; @@ -33,14 +33,14 @@ uint32_t tasking_tmpStack[KSTACKSIZE]; void tasking_init() { cli(); kernel_process = kmalloc(sizeof(struct process)); //This process must be hidden to users - kernel_process->pid = kernel_process->uid = kernel_process->threads = 0; + kernel_process->pid = kernel_process->uid = kernel_process->thread_count = 0; kernel_process->privilege = PL_KERNEL; kernel_process->parent = kernel_process; kernel_process->pagedir = kernel_pagedir; kernel_process->next = 0; current_thread = 0; idle_thread = thread_new(kernel_process, task_idle, 0); - threads = 0; //Do not include idle thread in threads + kernel_process->threads = idle_thread; sti(); monitor_write("[Tasking] "); } @@ -158,7 +158,7 @@ void thread_exit2(uint32_t reason) { //See EX_TH_* defines in task.h struct thread *th = current_thread; if (th == 0 || th->process == 0) goto retrn; struct process *pr = th->process; - if ((reason == EX_TH_NORMAL || reason == EX_TH_EXCEPTION) && pr->threads > 1) { + if ((reason == EX_TH_NORMAL || reason == EX_TH_EXCEPTION) && pr->thread_count > 1) { thread_delete(th); } else { process_delete(pr); @@ -247,7 +247,8 @@ static void thread_run(struct thread *thread, thread_entry entry_point, void *da struct thread *thread_new(struct process *proc, thread_entry entry_point, void *data) { struct thread *t = kmalloc(sizeof(struct thread)); t->process = proc; - proc->threads++; + t->next = 0; + proc->thread_count++; if (proc->privilege >= PL_SERVICE) { //We are running in user mode proc->stacksBottom -= USER_STACK_SIZE; @@ -271,10 +272,10 @@ struct thread *thread_new(struct process *proc, thread_entry entry_point, void * t->state = TS_RUNNING; sched_enqueue(t); - if (threads == 0) { - threads = t; + if (proc->threads == 0) { + proc->threads = t; } else { - struct thread *i = threads; + struct thread *i = proc->threads; while (i->next != 0) i = i->next; i->next = t; } @@ -286,7 +287,7 @@ struct process *process_new(struct process* parent, uint32_t uid, uint32_t privi struct process* p = kmalloc(sizeof(struct process)); p->pid = (nextpid++); p->uid = uid; - p->threads = 0; + p->thread_count = 0; p->privilege = privilege; p->parent = parent; p->pagedir = pagedir_new(); @@ -307,10 +308,10 @@ struct process *process_new(struct process* parent, uint32_t uid, uint32_t privi /* Deletes given thread, freeing the stack(s). */ static void thread_delete(struct thread *th) { - if (threads == th) { - threads = th->next; + if (th->process->threads == th) { + th->process->threads = th->next; } else { - struct thread *it = threads; + struct thread *it = th->process->threads; while (it) { if (it->next == th) { it->next = th->next; @@ -320,7 +321,7 @@ static void thread_delete(struct thread *th) { } } if (current_thread == th) current_thread = 0; - th->process->threads--; + th->process->thread_count--; kfree(th->kernelStack_addr); if (th->userStack_seg != 0) seg_unmap(th->userStack_seg); kfree(th); @@ -328,14 +329,10 @@ static void thread_delete(struct thread *th) { /* Deletes a process. First, deletes all its threads. Also deletes the corresponding page directory. */ static void process_delete(struct process *pr) { - struct thread *it = threads; + struct thread *it = pr->threads; while (it != 0) { - if (it->process == pr) { - thread_delete(it); - it = threads; - } else { - it = it->next; - } + thread_delete(it); + it = it->next; } obj_closeall(pr); if (processes == pr) { diff --git a/src/kernel/task/task.h b/src/kernel/task/task.h index a664258..0a95e57 100644 --- a/src/kernel/task/task.h +++ b/src/kernel/task/task.h @@ -23,7 +23,7 @@ typedef void (*thread_entry)(void*); struct process { - uint32_t pid, uid, privilege, threads; + uint32_t pid, uid, privilege, thread_count; struct process *parent; struct page_directory *pagedir; size_t stacksBottom; @@ -34,6 +34,7 @@ struct process { struct segment_map *heapseg; struct process *next; //Forms a linked list + struct thread *threads; }; struct thread { -- cgit v1.2.3