Main Page | Alphabetical List | Class List | File List | Class Members | File Members

scheduler.h File Reference

#include "copyright.h"
#include "list.h"
#include "thread.h"

Go to the source code of this file.

Classes

class  Scheduler

Defines

#define SCHED()   siglongjmp(schd_jmp, 1)

Functions

void SetPreemption ()
void timerInit ()
void schedule ()

Variables

sigset_t timer_mask


Define Documentation

 
#define SCHED  )     siglongjmp(schd_jmp, 1)
 

Definition at line 19 of file scheduler.h.

Referenced by Thread::Sleep(), and Thread::Suspend().


Function Documentation

void schedule  ) 
 

Definition at line 198 of file scheduler.cc.

00199 { 00200 Thread *nextThread = 0; 00201 00202 // disarm the alarm 00203 timer_settime(timer_id, 0, &timer_empty, 0); 00204 00205 nextThread = scheduler->FindNextToRun(); 00206 00207 if (threadToBeDestroyed != NULL) 00208 { 00209 currentThread = 0; 00210 DEBUG('t', "Purge Thread \"%s\"\n", threadToBeDestroyed->getName()); 00211 delete threadToBeDestroyed; 00212 threadToBeDestroyed = NULL; 00213 } 00214 00215 if (nextThread != NULL) 00216 { 00217 if (currentThread) 00218 scheduler->ReadyToRun(currentThread); // set to READY 00219 00220 currentThread = nextThread; // switch to the next thread 00221 //swap over here 00222 if (!currentThread->started) 00223 { 00224 currentThread->started = 1; 00225 currentThread->setStatus(RUNNING); // set to RUNNING 00226 DEBUG('t', "^Create^ \"%s\"\n", currentThread->getName()); 00227 interrupt->Enable(); 00228 timer_settime(timer_id, 0, &timer_value, 0); 00229 // use the NachOS switch to get the thread going for the 00230 // time and then begin to use the siglongjmp way 00231 SWITCH(&bogus_th, currentThread); 00232 } 00233 else 00234 { 00235 DEBUG('t', "Sched \"%s\"\n", currentThread->getName()); 00236 currentThread->setStatus(RUNNING); // set to RUNNING 00237 interrupt->Enable(); 00238 timer_settime(timer_id, 0, &timer_value, 0); 00239 siglongjmp(currentThread->cbuff, 1); 00240 } 00241 } 00242 else if (currentThread)// only a single thread is left 00243 { 00244 DEBUG('t', "Only Thread \"%s\"\n", currentThread->getName()); 00245 currentThread->setStatus(RUNNING); // set to RUNNING 00246 interrupt->Enable(); 00247 timer_settime(timer_id, 0, &timer_value, 0); 00248 sigprocmask(SIG_UNBLOCK, &timer_mask, 0); 00249 siglongjmp(currentThread->cbuff, 1); 00250 } 00251 else 00252 { 00253 // we are spinning while something is sleeping 00254 interrupt->Enable(); 00255 timer_settime(timer_id, 0, &timer_value, 0); 00256 } 00257 }

void SetPreemption  ) 
 

Definition at line 45 of file scheduler.cc.

References preempt.

00046 { 00047 preempt = true; 00048 }

void timerInit  ) 
 

Definition at line 162 of file scheduler.cc.

References NSECS_PER_SEC, timer_empty, timer_id, timer_mask, and timer_value.

Referenced by main().

00163 { 00164 struct sigaction tact; 00165 00166 //setup the timer handler and tell it to use an alternative signal stack 00167 memset(&tact, 0, sizeof(struct sigaction)); 00168 tact.sa_handler = Scheduler::timerIntH; 00169 tact.sa_flags = 0; 00170 sigemptyset(&tact.sa_mask); 00171 00172 sigemptyset(&timer_mask); 00173 sigaddset(&timer_mask, SIGALRM); 00174 00175 if (sigaction(SIGALRM, &tact, NULL) != 0) 00176 printf("Failed to set the alarm handler\n"); 00177 00178 timer_create(CLOCK_REALTIME, 0, &timer_id); 00179 memset(&timer_value, 0, sizeof(struct itimerspec)); 00180 memset(&timer_empty, 0, sizeof(struct itimerspec)); 00181 timer_value.it_value.tv_sec = 0; 00182 timer_value.it_value.tv_nsec = NSECS_PER_SEC / 15; // 0.0666 sec 00183 timer_settime(timer_id, 0, &timer_value, 0); 00184 }


Variable Documentation

sigset_t timer_mask
 

Definition at line 33 of file scheduler.cc.

Referenced by schedule(), Interrupt::SetLevel(), and timerInit().


Generated on Thu Sep 16 12:33:46 2004 for NachOS by doxygen 1.3.8