From: John Hodge Date: Sun, 1 Apr 2012 03:26:12 +0000 (+0800) Subject: Kernel/threads - Adding PGIDs, made processes have a list X-Git-Tag: rel0.15~711^2~1 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=16a3122b498e81b7aa515a4f21c03aff8e790e50;p=tpg%2Facess2.git Kernel/threads - Adding PGIDs, made processes have a list --- diff --git a/KernelLand/Kernel/include/acess.h b/KernelLand/Kernel/include/acess.h index 5b9effbf..c8cff886 100644 --- a/KernelLand/Kernel/include/acess.h +++ b/KernelLand/Kernel/include/acess.h @@ -504,6 +504,7 @@ extern void Threads_Exit(int TID, int Status); extern void Threads_Yield(void); extern void Threads_Sleep(void); extern int Threads_WakeTID(tTID Thread); +extern tPGID Threads_GetPGID(void); extern tPID Threads_GetPID(void); extern tTID Threads_GetTID(void); extern tUID Threads_GetUID(void); diff --git a/KernelLand/Kernel/threads.c b/KernelLand/Kernel/threads.c index 63671724..e22994bf 100644 --- a/KernelLand/Kernel/threads.c +++ b/KernelLand/Kernel/threads.c @@ -1,5 +1,6 @@ /* - * Acess2 + * Acess2 Kernel + * - By John Hodge (thePowersGang) * threads.c * - Common Thread Control */ @@ -125,14 +126,6 @@ void Threads_Init(void) Log_Debug("Threads", ".KernelStack = %i", offsetof(tThread, KernelStack)); // Create Initial Task -// #if SCHEDULER_TYPE == SCHED_RR_PRI -// gaActiveThreads[gThreadZero.Priority].Head = &gThreadZero; -// gaActiveThreads[gThreadZero.Priority].Tail = &gThreadZero; -// #else -// gActiveThreads.Head = &gThreadZero; -// gActiveThreads.Tail = &gThreadZero; -// #endif - gAllThreads = &gThreadZero; giNumActiveThreads = 1; gThreadZero.Process = &gProcessZero; @@ -149,6 +142,25 @@ void Threads_Delete(tThread *Thread) Proc_ClearThread(Thread); Thread->Process->nThreads --; + + if( Thread->Process->FirstThread == Thread ) + { + Thread->Process->FirstThread = Thread->ProcessNext; + } + else + { + tThread *prev = Thread->Process->FirstThread; + while(prev && prev->ProcessNext != Thread) + prev = prev->ProcessNext; + if( !prev ) + Log_Error("Threads", "Thread %p(%i %s) is not on the process's list", + Thread, Thread->TID, Thread->ThreadName + ); + else + prev->ProcessNext = Thread->ProcessNext; + } + + // If the final thread is being terminated, clean up the process if( Thread->Process->nThreads == 0 ) { tProcess *proc = Thread->Process; @@ -906,42 +918,8 @@ void Threads_AddActive(tThread *Thread) */ tThread *Threads_RemActive(void) { - #if 0 - tThread *ret = Proc_GetCurThread(); - - if( !IS_LOCKED(&glThreadListLock) ) { - Log_KernelPanic("Threads", "Threads_RemActive called without lock held"); - return NULL; - } - - // Delete from active queue - #if SCHEDULER_TYPE == SCHED_RR_PRI - if( !Threads_int_DelFromQueue(&gaActiveThreads[ret->Priority], ret) ) - #else - if( !Threads_int_DelFromQueue(&gActiveThreads, ret) ) - #endif - { - Log_Warning("Threads", "Current thread %p(%i %s) is not on active queue", - ret, ret->TID, ret->ThreadName - ); - return NULL; - } - - ret->Next = NULL; - ret->Remaining = 0; - - // no need to decrement tickets, scheduler did it for us - - #if SCHEDULER_TYPE == SCHED_LOTTERY && DEBUG_TRACE_TICKETS - Log("CPU%i %p (%i %s) removed, giFreeTickets = %i [nc]", - GetCPUNum(), ret, ret->TID, ret->ThreadName, giFreeTickets); - #endif - - return ret; - #else giNumActiveThreads --; return Proc_GetCurThread(); - #endif } /**