Fixed bug in keyboard driver on real hardware (aux p/s2 port code)
[tpg/acess2.git] / Kernel / threads.c
index 890f32d..96a38da 100644 (file)
@@ -25,7 +25,7 @@ extern int    Proc_Clone(Uint *Err, Uint Flags);
 
 // === PROTOTYPES ===
 void   Threads_Init();
-void   Threads_SetName(char *NewName);
+ int   Threads_SetName(char *NewName);
 char   *Threads_GetName(int ID);
 void   Threads_SetTickets(int Num);
 tThread        *Threads_CloneTCB(Uint *Err, Uint Flags);
@@ -118,13 +118,14 @@ void Threads_Init()
  * \fn void Threads_SetName(char *NewName)
  * \brief Sets the current thread's name
  */
-void Threads_SetName(char *NewName)
+int Threads_SetName(char *NewName)
 {
        tThread *cur = Proc_GetCurThread();
        if( IsHeap(cur->ThreadName) )
                free( cur->ThreadName );
        cur->ThreadName = malloc(strlen(NewName)+1);
        strcpy(cur->ThreadName, NewName);
+       return 0;
 }
 
 /**
@@ -467,7 +468,7 @@ void Threads_Sleep()
        tThread *cur = Proc_GetCurThread();
        tThread *thread;
        
-       Log("Proc_Sleep: %i going to sleep", cur->TID);
+       //Log_Log("Threads", "%i going to sleep", cur->TID);
        
        // Acquire Spinlock
        LOCK( &giThreadListLock );
@@ -521,11 +522,14 @@ void Threads_Wake(tThread *Thread)
        {
        case THREAD_STAT_ACTIVE:        break;
        case THREAD_STAT_SLEEPING:
+               //Log_Log("Threads", "Waking %i (%p) from sleeping", Thread->TID, Thread);
                LOCK( &giThreadListLock );
                prev = Threads_int_GetPrev(&gSleepingThreads, Thread);
                prev->Next = Thread->Next;      // Remove from sleeping queue
                Thread->Next = gActiveThreads;  // Add to active queue
                gActiveThreads = Thread;
+               giNumActiveThreads ++;
+               giTotalTickets += Thread->NumTickets;
                Thread->Status = THREAD_STAT_ACTIVE;
                RELEASE( &giThreadListLock );
                break;
@@ -541,6 +545,11 @@ void Threads_Wake(tThread *Thread)
        }
 }
 
+void Threads_WakeTID(tTID Thread)
+{
+       Threads_Wake( Threads_GetThread(Thread) );
+}
+
 /**
  * \fn void Threads_AddActive(tThread *Thread)
  * \brief Adds a thread to the active queue
@@ -610,21 +619,23 @@ void Threads_SendSignal(int TID, int Num)
 #endif
 
 // --- Process Structure Access Functions ---
-int Threads_GetPID()
+tPID Threads_GetPID()
 {
        return Proc_GetCurThread()->TGID;
 }
-int Threads_GetTID()
+tTID Threads_GetTID()
 {
        return Proc_GetCurThread()->TID;
 }
 tUID Threads_GetUID()
 {
-       tThread *t = Proc_GetCurThread();
-       int ret = t->UID;
-       Log("Threads_GetUID: TID %i, return %i", t->TID, ret);
-       return ret;
+       return Proc_GetCurThread()->UID;
+}
+tGID Threads_GetGID()
+{
+       return Proc_GetCurThread()->GID;
 }
+
 int Threads_SetUID(Uint *Errno, tUID ID)
 {
        tThread *t = Proc_GetCurThread();
@@ -637,10 +648,6 @@ int Threads_SetUID(Uint *Errno, tUID ID)
        return 0;
 }
 
-tGID Threads_GetGID()
-{
-       return Proc_GetCurThread()->GID;
-}
 int Threads_SetGID(Uint *Errno, tGID ID)
 {
        tThread *t = Proc_GetCurThread();
@@ -692,10 +699,15 @@ tThread *Threads_GetNextToRun(int CPU)
         int    ticket;
         int    number;
        
-       if(giNumActiveThreads == 0)     return NULL;
+       if(giNumActiveThreads == 0) {
+               //Log_Debug("Threads", "CPU%i has no threads to run", CPU);
+               return NULL;
+       }
        
        // Special case: 1 thread
        if(giNumActiveThreads == 1) {
+               //Log_Debug("Threads", "CPU%i has only one thread %i %s",
+               //      CPU, gActiveThreads->TID, gActiveThreads->ThreadName);
                return gActiveThreads;
        }
        
@@ -723,6 +735,9 @@ tThread *Threads_GetNextToRun(int CPU)
                        giTotalTickets, number);
        }
        
+       //Log_Debug("Threads", "Switching CPU%i to %p (%s)",
+       //      CPU, thread, thread->ThreadName);
+       
        return thread;
 }
 

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