Kernel - Updated thread code to add new active tasks to the end of the queue
authorJohn Hodge <[email protected]>
Sun, 7 Aug 2011 03:44:53 +0000 (11:44 +0800)
committerJohn Hodge <[email protected]>
Sun, 7 Aug 2011 03:44:53 +0000 (11:44 +0800)
- Also halved the default quantum - To improve responsiveness

Kernel/threads.c

index c4169fe..4ab76ff 100644 (file)
@@ -7,6 +7,7 @@
 #include <threads.h>
 #include <threads_int.h>
 #include <errno.h>
+#include <mutex.h>
 #include <semaphore.h>
 
 // Configuration
@@ -23,7 +24,7 @@
 #define SCHEDULER_TYPE SCHED_RR_PRI
 
 // === CONSTANTS ===
-#define        DEFAULT_QUANTUM 10
+#define        DEFAULT_QUANTUM 5
 #define        DEFAULT_PRIORITY        5
 #define MIN_PRIORITY           10
 const enum eConfigTypes        cCONFIG_TYPES[] = {
@@ -861,13 +862,23 @@ void Threads_AddActive(tThread *Thread)
        Thread->Status = THREAD_STAT_ACTIVE;
 //     Thread->CurCPU = -1;
        // Add to active list
-       #if SCHEDULER_TYPE == SCHED_RR_PRI
-       Thread->Next = gaActiveThreads[Thread->Priority];
-       gaActiveThreads[Thread->Priority] = Thread;
-       #else
-       Thread->Next = gActiveThreads;
-       gActiveThreads = Thread;
-       #endif
+       {
+               tThread *tmp, *prev = NULL;
+               #if SCHEDULER_TYPE == SCHED_RR_PRI
+               for( tmp = gaActiveThreads[Thread->Priority]; tmp; prev = tmp, tmp = tmp->Next );
+               if(prev)
+                       prev->Next = Thread;
+               else
+                       gaActiveThreads[Thread->Priority] = Thread;
+               #else
+               for( tmp = gActiveThreads; tmp; prev = tmp, tmp = tmp->Next );
+               if(prev)
+                       prev->Next = Thread;
+               else
+                       gActiveThreads = Thread;
+               #endif
+               Thread->Next = NULL;
+       }
        
        // Update bookkeeping
        giNumActiveThreads ++;

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