/** ***************************************************************** * \fn void TPOS_Yield(void) * Give the CPU time to an other thread. If the current thread * is the main thread sentence it to death and create a new one ***************************************************************** */ void TPOS_Yield(void) { Thread *newTh; EV_Trigger(&Thread_Current()->wakeEvent); newTh = GetNewThread(); if(newTh) { Thread_Switch(newTh); } else { /* Out of threads == Big shit */ } }
//--------------------------------------------------------------------------- void ThreadPort_StartThreads() { KernelSWI_Config(); // configure the task switch SWI KernelTimer_Config(); // configure the kernel timer Scheduler_SetScheduler(1); // enable the scheduler Scheduler_Schedule(); // run the scheduler - determine the first Thread_t to run Thread_Switch(); // Set the next scheduled Thread_t to the current Thread_t KernelTimer_Start(); // enable the kernel timer KernelSWI_Start(); // enable the task switch SWI ThreadPort_StartFirstThread(); // Jump to the first Thread_t (does not return) }
//--------------------------------------------------------------------------- void ThreadPort_StartThreads() { KernelSWI_Config(); // configure the task switch SWI KernelTimer_Config(); // configure the kernel timer Scheduler_SetScheduler(1); // enable the scheduler Scheduler_Schedule(); // run the scheduler - determine the first thread to run Thread_Switch(); // Set the next scheduled thread to the current thread KernelTimer_Start(); // enable the kernel timer KernelSWI_Start(); // enable the task switch SWI // Restore the context... Thread_RestoreContext(); // restore the context of the first running thread ASM("reti"); // return from interrupt - will return to the first scheduled thread }
/* ********************************************************************** * \fn void Mutex_Lock(Mutex *rs) * Wenn ein Prozess eingeschläfert wird muss ein neuer auf die * Haupt eventschleife angesetzt werden. There is no need * for creating a new thread here because the thread which owns the * RSEMA must exist * Falsch denn Eine RSEMA is owned by event. So there is a need for * running a new thread: ********************************************************************** */ void Mutex_Lock(Mutex *rs) { Thread *newTh; while(1) { if(!rs->owner) { /* Shit, because of pool it is not a thread-owned semaphore */ rs->owner = Thread_Current(); return; } else { //Con_Printf_P("Rsema is NOT FREE\n"); Thread_Current()->waitNext = rs->waitHead; rs->waitHead = Thread_Current(); newTh = GetNewThread(); if(newTh) { Thread_Switch(newTh); } else { /* Shit out of threads, which thread should I call now ? */ } } } }
/** **************************************************************** * \fn static void CSema_Down(EvCSema *cs) * Darf nicht aus Interrupt aufgerufen werden, * Wenn es einen Prozess einschläfert muss es einen neuen * auf main ansetzen. **************************************************************** */ void CSema_Down(CSema *cs) { Flags_t flags; Thread *newTh; while(1) { flags = save_ipl_set(IPL_EVENTS); if(cs->cnt > 0) { cs->cnt--; restore_ipl(flags); return; } Thread_Current()->waitNext = cs->waitHead; cs->waitHead = Thread_Current(); newTh = GetNewThread(); if(newTh) { restore_ipl(flags); Thread_Switch(newTh); } else { while(1); } } }
static void TPos_ThreadWake(void *eventData) { Thread *nextTh = eventData; MoveRunningToUnused(Thread_Current()); Thread_Switch(nextTh); }