tThread *t = Threads_GetThread(TID);
int initStatus = t->Status;
int ret;
- while(t->Status == initStatus) Threads_Yield();
+
+ if(initStatus != THREAD_STAT_ZOMBIE)
+ while(t->Status == initStatus) {
+ Threads_Yield();
+ }
+
ret = t->RetStatus;
switch(t->Status)
{
}
/**
- * \fn tThread *Threads_int_GetPrev(tThread *List, tThread *Thread)
+ * \fn tThread *Threads_int_GetPrev(tThread **List, tThread *Thread)
* \brief Gets the previous entry in a thead linked list
*/
tThread *Threads_int_GetPrev(tThread **List, tThread *Thread)
Threads_Kill( Proc_GetCurThread(), (Uint)Status & 0xFF );
else
Threads_Kill( Threads_GetThread(TID), (Uint)Status & 0xFF );
+ for(;;) HALT(); // Just in case
}
/**
* \fn void Threads_Kill(tThread *Thread, int Status)
* \brief Kill a thread
- * \param TID Thread ID (0 for current)
+ * \param Thread Thread to kill
+ * \param Status Status code to return to the parent
*/
void Threads_Kill(tThread *Thread, int Status)
{
// Release spinlocks
RELEASE( &Thread->IsLocked ); // Released first so that it IS released
RELEASE( &giThreadListLock );
+
+ //Log("Thread %i went *hurk*", Thread->TID);
+
if(Status != -1) HALT();
}
// Get thread before current thread
thread = Threads_int_GetPrev( &gActiveThreads, cur );
if(!thread) {
- Warning("Proc_Sleep - Current thread is not on the active queue");
+ Warning("Threads_Sleep - Current thread is not on the active queue");
+ Threads_Dump();
return;
}
// Release Spinlock
RELEASE( &giThreadListLock );
- HALT();
+ while(cur->Status != THREAD_STAT_ACTIVE) HALT();
}
-/**c0108919:
+/**
* \fn void Threads_Wake( tThread *Thread )
* \brief Wakes a sleeping/waiting thread up
*/
void Threads_Dump()
{
tThread *thread;
+ tThread *cur = Proc_GetCurThread();
Log("Active Threads:");
for(thread=gActiveThreads;thread;thread=thread->Next)
{
- Log(" %i (%i) - %s", thread->TID, thread->TGID, thread->ThreadName);
+ Log("%c%i (%i) - %s",
+ (thread==cur?'*':' '),
+ thread->TID, thread->TGID, thread->ThreadName);
Log(" %i Tickets, Quantum %i", thread->NumTickets, thread->Quantum);
Log(" KStack 0x%x", thread->KernelStack);
}
Log("Sleeping Threads:");
for(thread=gSleepingThreads;thread;thread=thread->Next)
{
- Log(" %i (%i) - %s", thread->TID, thread->TGID, thread->ThreadName);
+ Log("%c%i (%i) - %s",
+ (thread==cur?'*':' '),
+ thread->TID, thread->TGID, thread->ThreadName);
Log(" %i Tickets, Quantum %i", thread->NumTickets, thread->Quantum);
Log(" KStack 0x%x", thread->KernelStack);
}
void Threads_SegFault(tVAddr Addr)
{
//Threads_SendSignal( Proc_GetCurThread()->TID, SIGSEGV );
- Log("Thread #%i committed a segfault at address %p\n", Proc_GetCurThread()->TID, Addr);
- Threads_Exit( 0, 0 );
+ Warning("Thread #%i committed a segfault at address %p", Proc_GetCurThread()->TID, Addr);
+ Threads_Exit( 0, -1 );
}