X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fthreads.c;h=ba0f430db5eb84de47ec034f929124dff89a7b0c;hb=30e30d7bc325852a8677819d11a47373b08d6271;hp=b9b299231e3271a028e41be1a4f24186fdfc9174;hpb=e266c901ab2bd1b7b249a80b5a556e6f7cbb34ba;p=tpg%2Facess2.git diff --git a/Kernel/threads.c b/Kernel/threads.c index b9b29923..ba0f430d 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -18,14 +18,14 @@ const enum eConfigTypes cCONFIG_TYPES[] = { }; // === IMPORTS === -extern void ArchThreads_Init(); -extern void Proc_Start(); -extern tThread *Proc_GetCurThread(); +extern void ArchThreads_Init(void); +extern void Proc_Start(void); +extern tThread *Proc_GetCurThread(void); extern int Proc_Clone(Uint *Err, Uint Flags); extern void Proc_CallFaultHandler(tThread *Thread); // === PROTOTYPES === -void Threads_Init(); +void Threads_Init(void); int Threads_SetName(char *NewName); char *Threads_GetName(int ID); void Threads_SetTickets(int Num); @@ -36,17 +36,17 @@ void Threads_AddToDelete(tThread *Thread); tThread *Threads_int_GetPrev(tThread **List, tThread *Thread); void Threads_Exit(int TID, int Status); void Threads_Kill(tThread *Thread, int Status); -void Threads_Yield(); -void Threads_Sleep(); +void Threads_Yield(void); +void Threads_Sleep(void); void Threads_Wake(tThread *Thread); void Threads_AddActive(tThread *Thread); - int Threads_GetPID(); - int Threads_GetTID(); -tUID Threads_GetUID(); + int Threads_GetPID(void); + int Threads_GetTID(void); +tUID Threads_GetUID(void); int Threads_SetUID(Uint *Errno, tUID ID); -tGID Threads_GetGID(); +tGID Threads_GetGID(void); int Threads_SetGID(Uint *Errno, tUID ID); -void Threads_Dump(); +void Threads_Dump(void); // === GLOBALS === // -- Core Thread -- @@ -72,7 +72,7 @@ tThread gThreadZero = { }; // -- Processes -- // --- Locks --- -volatile int giThreadListLock = 0; ///\note NEVER use a heap function while locked +tSpinlock glThreadListLock = 0; ///\note NEVER use a heap function while locked // --- Current State --- volatile int giNumActiveThreads = 0; volatile int giTotalTickets = 0; @@ -85,10 +85,10 @@ tThread *gDeleteThreads = NULL; // Threads to delete // === CODE === /** - * \fn void Threads_Init() + * \fn void Threads_Init(void) * \brief Initialse the thread list */ -void Threads_Init() +void Threads_Init(void) { ArchThreads_Init(); @@ -151,12 +151,12 @@ void Threads_SetTickets(int Num) if(Num < 0) return; if(Num > MAX_TICKETS) Num = MAX_TICKETS; - LOCK( &giThreadListLock ); + LOCK( &glThreadListLock ); giTotalTickets -= cur->NumTickets; cur->NumTickets = Num; giTotalTickets += Num; //LOG("giTotalTickets = %i", giTotalTickets); - RELEASE( &giThreadListLock ); + RELEASE( &glThreadListLock ); } /** @@ -173,6 +173,7 @@ tThread *Threads_CloneTCB(Uint *Err, Uint Flags) *Err = -ENOMEM; return NULL; } + memcpy(new, cur, sizeof(tThread)); new->Next = NULL; new->IsLocked = 0; @@ -184,8 +185,7 @@ tThread *Threads_CloneTCB(Uint *Err, Uint Flags) new->PTID = cur->TID; // Clone Name - new->ThreadName = malloc(strlen(cur->ThreadName)+1); - strcpy(new->ThreadName, cur->ThreadName); + new->ThreadName = strdup(cur->ThreadName); // Set Thread Group ID (PID) if(Flags & CLONE_VM) @@ -402,7 +402,7 @@ void Threads_Kill(tThread *Thread, int Status) LOCK( &Thread->IsLocked ); // Lock thread list - LOCK( &giThreadListLock ); + LOCK( &glThreadListLock ); // Get previous thread on list prev = Threads_int_GetPrev( &gActiveThreads, Thread ); @@ -440,7 +440,7 @@ void Threads_Kill(tThread *Thread, int Status) // Release spinlocks RELEASE( &Thread->IsLocked ); // Released first so that it IS released - RELEASE( &giThreadListLock ); + RELEASE( &glThreadListLock ); //Log("Thread %i went *hurk*", Thread->TID); @@ -448,20 +448,20 @@ void Threads_Kill(tThread *Thread, int Status) } /** - * \fn void Threads_Yield() + * \fn void Threads_Yield(void) * \brief Yield remainder of timeslice */ -void Threads_Yield() +void Threads_Yield(void) { Proc_GetCurThread()->Remaining = 0; HALT(); } /** - * \fn void Threads_Sleep() + * \fn void Threads_Sleep(void) * \brief Take the current process off the run queue */ -void Threads_Sleep() +void Threads_Sleep(void) { tThread *cur = Proc_GetCurThread(); tThread *thread; @@ -469,7 +469,7 @@ void Threads_Sleep() //Log_Log("Threads", "%i going to sleep", cur->TID); // Acquire Spinlock - LOCK( &giThreadListLock ); + LOCK( &glThreadListLock ); // Get thread before current thread thread = Threads_int_GetPrev( &gActiveThreads, cur ); @@ -481,7 +481,7 @@ void Threads_Sleep() // Don't sleep if there is a message waiting if( cur->Messages ) { - RELEASE( &giThreadListLock ); + RELEASE( &glThreadListLock ); return; } @@ -503,7 +503,7 @@ void Threads_Sleep() cur->Status = THREAD_STAT_SLEEPING; // Release Spinlock - RELEASE( &giThreadListLock ); + RELEASE( &glThreadListLock ); while(cur->Status != THREAD_STAT_ACTIVE) HALT(); } @@ -521,7 +521,7 @@ 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 ); + LOCK( &glThreadListLock ); prev = Threads_int_GetPrev(&gSleepingThreads, Thread); prev->Next = Thread->Next; // Remove from sleeping queue Thread->Next = gActiveThreads; // Add to active queue @@ -529,7 +529,7 @@ void Threads_Wake(tThread *Thread) giNumActiveThreads ++; giTotalTickets += Thread->NumTickets; Thread->Status = THREAD_STAT_ACTIVE; - RELEASE( &giThreadListLock ); + RELEASE( &glThreadListLock ); break; case THREAD_STAT_WAITING: Warning("Thread_Wake - Waiting threads are not currently supported"); @@ -554,14 +554,14 @@ void Threads_WakeTID(tTID Thread) */ void Threads_AddActive(tThread *Thread) { - LOCK( &giThreadListLock ); + LOCK( &glThreadListLock ); Thread->Next = gActiveThreads; gActiveThreads = Thread; giNumActiveThreads ++; giTotalTickets += Thread->NumTickets; //Log("Threads_AddActive: giNumActiveThreads = %i, giTotalTickets = %i", // giNumActiveThreads, giTotalTickets); - RELEASE( &giThreadListLock ); + RELEASE( &glThreadListLock ); } /** @@ -612,19 +612,19 @@ void Threads_Fault(int Num) } // --- Process Structure Access Functions --- -tPID Threads_GetPID() +tPID Threads_GetPID(void) { return Proc_GetCurThread()->TGID; } -tTID Threads_GetTID() +tTID Threads_GetTID(void) { return Proc_GetCurThread()->TID; } -tUID Threads_GetUID() +tUID Threads_GetUID(void) { return Proc_GetCurThread()->UID; } -tGID Threads_GetGID() +tGID Threads_GetGID(void) { return Proc_GetCurThread()->GID; } @@ -654,10 +654,10 @@ int Threads_SetGID(Uint *Errno, tGID ID) } /** - * \fn void Threads_Dump() + * \fn void Threads_Dump(void) * \brief Dums a list of currently running threads */ -void Threads_Dump() +void Threads_Dump(void) { tThread *thread; tThread *cur = Proc_GetCurThread();