* threads.c
* - Common Thread Control
*/
+#define DEBUG 0
#include <acess.h>
#include <threads.h>
#include <threads_int.h>
*/
tThread *Threads_CloneTCB(Uint Flags)
{
- tThread *cur, *new;
- cur = Proc_GetCurThread();
+ tThread *cur = Proc_GetCurThread();
// Allocate and duplicate
- new = malloc(sizeof(tThread));
+ tThread *new = malloc(sizeof(tThread));
if(new == NULL) { errno = -ENOMEM; return NULL; }
memcpy(new, cur, sizeof(tThread));
void Threads_int_WaitForStatusEnd(enum eThreadStatus Status)
{
tThread *us = Proc_GetCurThread();
+ LOG("us = %p(%i %s), status=%i", us, us->TID, us->ThreadName, Status);
ASSERT(Status != THREAD_STAT_ACTIVE);
ASSERT(Status != THREAD_STAT_DEAD);
while( us->Status == Status )
// Single-list round-robin
// -----------------------------------
tThread *thread = gActiveThreads.Head;
+ LOG("thread = %p", thread);
if( thread )
{
gActiveThreads.Head = thread->Next;
*/
tThread *Threads_GetNextToRun(int CPU, tThread *Last)
{
- // If this CPU has the lock, we must let it complete
- if( CPU_HAS_LOCK( &glThreadListLock ) )
- return Last;
+ ASSERT( CPU_HAS_LOCK(&glThreadListLock) );
// Don't change threads if the current CPU has switches disabled
- if( gaThreads_NoTaskSwitch[CPU] )
+ if( gaThreads_NoTaskSwitch[CPU] ) {
+ LOG("- Denied");
return Last;
-
- // Lock thread list
- SHORTLOCK( &glThreadListLock );
+ }
// Make sure the current (well, old) thread is marked as de-scheduled
if(Last) Last->CurCPU = -1;
// No active threads, just take a nap
if(giNumActiveThreads == 0) {
- SHORTREL( &glThreadListLock );
+ LOG("- No active");
#if DEBUG_TRACE_TICKETS
Log("No active threads");
#endif
// Call actual scheduler
tThread *thread = Threads_int_GetRunnable();
-
+
// Anything to do?
if( thread )
{
Warning("No runnable thread for CPU%i", CPU);
}
- SHORTREL( &glThreadListLock );
-
return thread;
}