X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fthreads.c;h=b5ce1917a182959ac2c7ea605f5cead79b0b644c;hb=e42035c38b65d428672b128f9ae253f81b2ced96;hp=2043bc42b85d852766bbb3e7eac56deb634274eb;hpb=635bc78017d8a4a16314a973e39c849b2afac795;p=tpg%2Facess2.git diff --git a/Kernel/threads.c b/Kernel/threads.c index 2043bc42..b5ce1917 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -32,22 +32,24 @@ const enum eConfigTypes cCONFIG_TYPES[] = { // === IMPORTS === 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); extern int GetCPUNum(void); // === PROTOTYPES === void Threads_Init(void); +#if 0 int Threads_SetName(const char *NewName); +#endif char *Threads_GetName(int ID); +#if 0 void Threads_SetPriority(tThread *Thread, int Pri); tThread *Threads_CloneTCB(Uint *Err, Uint Flags); int Threads_WaitTID(int TID, int *status); tThread *Threads_GetThread(Uint TID); +#endif void Threads_AddToDelete(tThread *Thread); tThread *Threads_int_DelFromQueue(tThread **List, tThread *Thread); +#if 0 void Threads_Exit(int TID, int Status); void Threads_Kill(tThread *Thread, int Status); void Threads_Yield(void); @@ -55,25 +57,32 @@ void Threads_Sleep(void); int Threads_Wake(tThread *Thread); void Threads_AddActive(tThread *Thread); tThread *Threads_RemActive(void); +#endif +void Threads_Fault(int Num); +void Threads_SegFault(tVAddr Addr); +#if 0 int Threads_GetPID(void); int Threads_GetTID(void); tUID Threads_GetUID(void); - int Threads_SetUID(Uint *Errno, tUID ID); tGID Threads_GetGID(void); + int Threads_SetUID(Uint *Errno, tUID ID); int Threads_SetGID(Uint *Errno, tUID ID); +#endif void Threads_Dump(void); void Threads_DumpActive(void); +#if 0 int Mutex_Acquire(tMutex *Mutex); void Mutex_Release(tMutex *Mutex); int Mutex_IsLocked(tMutex *Mutex); +#endif // === GLOBALS === // -- Core Thread -- // Only used for the core kernel tThread gThreadZero = { Status: THREAD_STAT_ACTIVE, // Status - ThreadName: "ThreadZero", // Name + ThreadName: (char*)"ThreadZero", // Name Quantum: DEFAULT_QUANTUM, // Default Quantum Remaining: DEFAULT_QUANTUM, // Current Quantum Priority: DEFAULT_PRIORITY // Number of tickets @@ -716,7 +725,7 @@ int Threads_Wake(tThread *Thread) switch(Thread->Status) { case THREAD_STAT_ACTIVE: - Log("Thread_Wake: Waking awake thread (%i)", Thread->TID); + Log("Threads_Wake - Waking awake thread (%i)", Thread->TID); return -EALREADY; case THREAD_STAT_SLEEPING: @@ -733,15 +742,15 @@ int Threads_Wake(tThread *Thread) return -EOK; case THREAD_STAT_WAITING: - Warning("Thread_Wake - Waiting threads are not currently supported"); + Warning("Threads_Wake - Waiting threads are not currently supported"); return -ENOTIMPL; case THREAD_STAT_DEAD: - Warning("Thread_Wake - Attempt to wake dead thread (%i)", Thread->TID); + Warning("Threads_Wake - Attempt to wake dead thread (%i)", Thread->TID); return -ENOTIMPL; default: - Warning("Thread_Wake - Unknown process status (%i)\n", Thread->Status); + Warning("Threads_Wake - Unknown process status (%i)\n", Thread->Status); return -EINTERNAL; } } @@ -887,6 +896,17 @@ void Threads_Fault(int Num) Proc_CallFaultHandler(thread); } +/** + * \fn void Threads_SegFault(tVAddr Addr) + * \brief Called when a Segment Fault occurs + */ +void Threads_SegFault(tVAddr Addr) +{ + Warning("Thread #%i committed a segfault at address %p", Proc_GetCurThread()->TID, Addr); + Threads_Fault( 1 ); + //Threads_Exit( 0, -1 ); +} + // --- Process Structure Access Functions --- tPID Threads_GetPID(void) { @@ -1220,17 +1240,6 @@ tThread *Threads_GetNextToRun(int CPU, tThread *Last) return thread; } -/** - * \fn void Threads_SegFault(tVAddr Addr) - * \brief Called when a Segment Fault occurs - */ -void Threads_SegFault(tVAddr Addr) -{ - Warning("Thread #%i committed a segfault at address %p", Proc_GetCurThread()->TID, Addr); - Threads_Fault( 1 ); - //Threads_Exit( 0, -1 ); -} - /** * \brief Acquire a heavy mutex * \param Mutex Mutex to acquire @@ -1303,6 +1312,7 @@ int Mutex_Acquire(tMutex *Mutex) /** * \brief Release a held mutex * \param Mutex Mutex to release + * \note Releasing a non-held mutex has no effect */ void Mutex_Release(tMutex *Mutex) { @@ -1350,9 +1360,11 @@ int Mutex_IsLocked(tMutex *Mutex) // void Semaphore_Init(tSemaphore *Sem, int Value, int MaxValue, const char *Module, const char *Name) { + memset(Sem, 0, sizeof(tSemaphore)); Sem->Value = Value; Sem->ModName = Module; Sem->Name = Name; + Sem->MaxValue = MaxValue; } // // Wait for items to be avaliable