From d4e3d74bb9ed79be25604e30231cd64e7091fdc2 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 7 Aug 2011 11:44:53 +0800 Subject: [PATCH] Kernel - Updated thread code to add new active tasks to the end of the queue - Also halved the default quantum - To improve responsiveness --- Kernel/threads.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Kernel/threads.c b/Kernel/threads.c index c4169fec..4ab76ff6 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -7,6 +7,7 @@ #include #include #include +#include #include // 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 ++; -- 2.20.1