#include <threads.h>
#include <threads_int.h>
#include <errno.h>
+#include <mutex.h>
#include <semaphore.h>
+#include <hal_proc.h>
// Configuration
#define DEBUG_TRACE_TICKETS 0 // Trace ticket counts
#define SCHED_RR_SIM 2 // Single Queue Round Robin
#define SCHED_RR_PRI 3 // Multi Queue Round Robin
// Set scheduler type
-#define SCHEDULER_TYPE SCHED_LOTTERY
+#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[] = {
};
// === IMPORTS ===
-extern void ArchThreads_Init(void);
-extern void Proc_CallFaultHandler(tThread *Thread);
-extern void Proc_DumpThreadCPUState(tThread *Thread);
-extern int GetCPUNum(void);
// === PROTOTYPES ===
void Threads_Init(void);
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 ++;
{
tThread *thread = Proc_GetCurThread();
- Log_Log("Threads", "Threads_Fault: thread = %p", thread);
-
if(!thread) return ;
Log_Log("Threads", "Threads_Fault: thread->FaultHandler = %p", thread->FaultHandler);
}
// If we fall onto the same queue again, special handling is
// needed
- if( i == Last->Priority ) {
+ if( Last && i == Last->Priority ) {
tThread *savedThread = thread;
// Find the next unscheduled thread in the list
else
taken = Sem->Value;
Sem->Value -= taken;
- SHORTREL( &Sem->Protector );
}
else
{