Kernel - So... should remember to initialise structures
[tpg/acess2.git] / Kernel / threads.c
index b1a2a61..73c3f3c 100644 (file)
@@ -35,12 +35,13 @@ 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);
- int   Threads_SetName(char *NewName);
+ int   Threads_SetName(const char *NewName);
 char   *Threads_GetName(int ID);
-void   Threads_SetTickets(tThread *Thread, int Num);
+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);
@@ -123,12 +124,12 @@ void Threads_Init(void)
 }
 
 /**
- * \fn void Threads_SetName(char *NewName)
+ * \fn void Threads_SetName(const char *NewName)
  * \brief Sets the current thread's name
  * \param NewName      New name for the thread
  * \return Boolean Failure
  */
-int Threads_SetName(char *NewName)
+int Threads_SetName(const char *NewName)
 {
        tThread *cur = Proc_GetCurThread();
        char    *oldname = cur->ThreadName;
@@ -662,6 +663,12 @@ void Threads_AddActive(tThread *Thread)
 {
        SHORTLOCK( &glThreadListLock );
        
+       if( Thread->Status == THREAD_STAT_ACTIVE ) {
+               tThread *cur = Proc_GetCurThread();
+               Warning("WTF, CPU%i %p (%i %s) is adding %p (%i %s) when it is active",
+                       GetCPUNum(), cur, cur->TID, cur->ThreadName, Thread, Thread->TID, Thread->ThreadName);
+       }
+       
        // Set state
        Thread->Status = THREAD_STAT_ACTIVE;
        Thread->CurCPU = -1;
@@ -680,8 +687,8 @@ void Threads_AddActive(tThread *Thread)
        #if SCHEDULER_TYPE == SCHED_LOTTERY
        giFreeTickets += caiTICKET_COUNTS[ Thread->Priority ];
        # if DEBUG_TRACE_TICKETS
-       Log("Threads_AddActive: %p %i (%s) added, new giFreeTickets = %i",
-               Thread, Thread->TID, Thread->ThreadName, giFreeTickets);
+       Log("Threads_AddActive: CPU%i %p %i (%s) added, new giFreeTickets = %i",
+               GetCPUNum(), Thread, Thread->TID, Thread->ThreadName, giFreeTickets);
        # endif
        #endif
        
@@ -718,8 +725,8 @@ tThread *Threads_RemActive(void)
        // no need to decrement tickets, scheduler did it for us
        
        #if SCHEDULER_TYPE == SCHED_LOTTERY && DEBUG_TRACE_TICKETS
-       Log("Threads_RemActive: %p %i (%s) removed, giFreeTickets = %i",
-               ret, ret->TID, ret->ThreadName, giFreeTickets);
+       Log("Threads_RemActive: CPU%i %p %i (%s) removed, giFreeTickets = %i",
+               GetCPUNum(), ret, ret->TID, ret->ThreadName, giFreeTickets);
        #endif
        
        SHORTREL( &glThreadListLock );
@@ -836,8 +843,8 @@ void Threads_DumpActive(void)
                for(thread=gActiveThreads;thread;thread=thread->Next)
        #endif
                {
-                       Log(" %i (%i) - %s (CPU %i)",
-                               thread->TID, thread->TGID, thread->ThreadName, thread->CurCPU);
+                       Log(" %p %i (%i) - %s (CPU %i)",
+                               thread, thread->TID, thread->TGID, thread->ThreadName, thread->CurCPU);
                        if(thread->Status != THREAD_STAT_ACTIVE)
                                Log("  ERROR State (%i) != THREAD_STAT_ACTIVE (%i)", thread->Status, THREAD_STAT_ACTIVE);
                        Log("  Priority %i, Quantum %i", thread->Priority, thread->Quantum);
@@ -863,9 +870,9 @@ void Threads_Dump(void)
        Log("All Threads:");
        for(thread=gAllThreads;thread;thread=thread->GlobalNext)
        {
-               Log(" %i (%i) - %s (CPU %i)",
-                       thread->TID, thread->TGID, thread->ThreadName, thread->CurCPU);
-               Log("  State %i", thread->Status);
+               Log(" %p %i (%i) - %s (CPU %i)",
+                       thread, thread->TID, thread->TGID, thread->ThreadName, thread->CurCPU);
+               Log("  State %i (%s)", thread->Status, casTHREAD_STAT[thread->Status]);
                switch(thread->Status)
                {
                case THREAD_STAT_MUTEXSLEEP:
@@ -909,7 +916,7 @@ tThread *Threads_GetNextToRun(int CPU, tThread *Last)
                thread = gDeleteThreads->Next;
                if( IS_LOCKED(&gDeleteThreads->IsLocked) ) {    // Only free if structure is unused
                        // Set to dead
-                       gDeleteThreads->Status = THREAD_STAT_DEAD;
+                       gDeleteThreads->Status = THREAD_STAT_BURIED;
                        // Free name
                        if( IsHeap(gDeleteThreads->ThreadName) )
                                free(gDeleteThreads->ThreadName);
@@ -1146,7 +1153,7 @@ void Mutex_Acquire(tMutex *Mutex)
                        Mutex->Waiting = us;
                        Mutex->LastWaiting = us;
                }
-               #if 1
+               #if 0
                {
                         int    i = 0;
                        tThread *t;
@@ -1167,6 +1174,12 @@ void Mutex_Acquire(tMutex *Mutex)
                Mutex->Owner = us;
                SHORTREL( &Mutex->Protector );
        }
+       
+       #if 0
+       extern tMutex   glPhysAlloc;
+       if( Mutex != &glPhysAlloc )
+               LogF("Mutex %p taken by %i %p\n", Mutex, us->TID, __builtin_return_address(0));
+       #endif
 }
 
 /**
@@ -1197,6 +1210,12 @@ void Mutex_Release(tMutex *Mutex)
                Mutex->Owner = NULL;
        }
        SHORTREL( &Mutex->Protector );
+       
+       #if 0
+       extern tMutex   glPhysAlloc;
+       if( Mutex != &glPhysAlloc )
+               LogF("Mutex %p released by %i %p\n", Mutex, Threads_GetTID(), __builtin_return_address(0));
+       #endif
 }
 
 /**

UCC git Repository :: git.ucc.asn.au