X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fthreads.c;h=96a38dacda3fc12160fb4657a9a73c615a54ce87;hb=0e9730abc6c9ba710a3f71356720a70d79e407ab;hp=075350dd6c2d426697665b310f574d62d70eadc8;hpb=f2fd50e797e6a3b3590e4c2e13b6782dd87c25a2;p=tpg%2Facess2.git diff --git a/Kernel/threads.c b/Kernel/threads.c index 075350dd..96a38dac 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -25,7 +25,7 @@ extern int Proc_Clone(Uint *Err, Uint Flags); // === PROTOTYPES === void Threads_Init(); -void Threads_SetName(char *NewName); + int Threads_SetName(char *NewName); char *Threads_GetName(int ID); void Threads_SetTickets(int Num); tThread *Threads_CloneTCB(Uint *Err, Uint Flags); @@ -118,13 +118,14 @@ void Threads_Init() * \fn void Threads_SetName(char *NewName) * \brief Sets the current thread's name */ -void Threads_SetName(char *NewName) +int Threads_SetName(char *NewName) { tThread *cur = Proc_GetCurThread(); if( IsHeap(cur->ThreadName) ) free( cur->ThreadName ); cur->ThreadName = malloc(strlen(NewName)+1); strcpy(cur->ThreadName, NewName); + return 0; } /** @@ -467,7 +468,7 @@ void Threads_Sleep() tThread *cur = Proc_GetCurThread(); tThread *thread; - Log("Proc_Sleep: %i going to sleep", cur->TID); + //Log_Log("Threads", "%i going to sleep", cur->TID); // Acquire Spinlock LOCK( &giThreadListLock ); @@ -521,11 +522,14 @@ void Threads_Wake(tThread *Thread) { case THREAD_STAT_ACTIVE: break; case THREAD_STAT_SLEEPING: + //Log_Log("Threads", "Waking %i (%p) from sleeping", Thread->TID, Thread); LOCK( &giThreadListLock ); prev = Threads_int_GetPrev(&gSleepingThreads, Thread); prev->Next = Thread->Next; // Remove from sleeping queue Thread->Next = gActiveThreads; // Add to active queue gActiveThreads = Thread; + giNumActiveThreads ++; + giTotalTickets += Thread->NumTickets; Thread->Status = THREAD_STAT_ACTIVE; RELEASE( &giThreadListLock ); break; @@ -541,6 +545,11 @@ void Threads_Wake(tThread *Thread) } } +void Threads_WakeTID(tTID Thread) +{ + Threads_Wake( Threads_GetThread(Thread) ); +} + /** * \fn void Threads_AddActive(tThread *Thread) * \brief Adds a thread to the active queue @@ -690,10 +699,15 @@ tThread *Threads_GetNextToRun(int CPU) int ticket; int number; - if(giNumActiveThreads == 0) return NULL; + if(giNumActiveThreads == 0) { + //Log_Debug("Threads", "CPU%i has no threads to run", CPU); + return NULL; + } // Special case: 1 thread if(giNumActiveThreads == 1) { + //Log_Debug("Threads", "CPU%i has only one thread %i %s", + // CPU, gActiveThreads->TID, gActiveThreads->ThreadName); return gActiveThreads; } @@ -721,6 +735,9 @@ tThread *Threads_GetNextToRun(int CPU) giTotalTickets, number); } + //Log_Debug("Threads", "Switching CPU%i to %p (%s)", + // CPU, thread, thread->ThreadName); + return thread; }