if( IsHeap(oldname) ) free( oldname );
cur->ThreadName = strdup(NewName);
-// Log_Debug("Threads", "Thread renamed to '%s'", NewName);
+ Log_Debug("Threads", "Thread renamed to '%s'", NewName);
return 0;
}
}
}
+void Threads_int_Sleep(enum eThreadStatus Status, void *Ptr, int Num, tThread **ListHead, tThread **ListTail, tShortSpinlock *Lock)
+{
+ SHORTLOCK( &glThreadListLock );
+ tThread *us = Threads_RemActive();
+ us->Next = NULL;
+ // - Mark as sleeping
+ us->Status = Status;
+ us->WaitPointer = Ptr;
+ us->RetStatus = Num; // Use RetStatus as a temp variable
+
+ // - Add to waiting
+ if( ListTail ) {
+ if(*ListTail) {
+ (*ListTail)->Next = us;
+ *ListTail = us;
+ }
+ else {
+ *ListHead = us;
+ *ListTail = us;
+ }
+ }
+ else {
+ *ListHead = us;
+ }
+
+ //if( Proc_ThreadSync(us) )
+ // return ;
+ SHORTREL( &glThreadListLock );
+ if( Lock )
+ SHORTLOCK( Lock );
+ Threads_int_WaitForStatusEnd(Status);
+}
+
/**
* \fn void Threads_Sleep(void)
* \brief Take the current process off the run queue
void Threads_int_DumpThread(tThread *thread)
{
+ if( !thread ) {
+ Log(" %p NULL", thread);
+ return ;
+ }
+ if( !CheckMem(thread, sizeof(tThread)) ) {
+ Log(" %p INVAL", thread);
+ return ;
+ }
+ tPID pid = (thread->Process ? thread->Process->PID : -1);
+ const char *statstr = (thread->Status < sizeof(casTHREAD_STAT)/sizeof(casTHREAD_STAT[0])
+ ? casTHREAD_STAT[thread->Status] : "");
Log(" %p %i (%i) - %s (CPU %i) - %i (%s)",
- thread, thread->TID, thread->Process->PID, thread->ThreadName, thread->CurCPU,
- thread->Status, casTHREAD_STAT[thread->Status]
+ thread, thread->TID, pid, thread->ThreadName, thread->CurCPU,
+ thread->Status, statstr
);
switch(thread->Status)
{
((tSemaphore*)thread->WaitPointer)->Name
);
break;
+ case THREAD_STAT_EVENTSLEEP:
+ // TODO: Event mask
+ break;
case THREAD_STAT_ZOMBIE:
Log(" Return Status: %i", thread->RetStatus);
break;
*/
void Threads_Dump(void)
{
- tThread *thread;
-
Log("--- Thread Dump ---");
Threads_DumpActive();
Log("All Threads:");
- for(thread=gAllThreads;thread;thread=thread->GlobalNext)
+ for(tThread *thread = gAllThreads; thread; thread = thread->GlobalNext)
{
Threads_int_DumpThread(thread);
}