1 package DEOS; 20 21 import gov.nasa.jpf.jvm.Verify; 22 23 24 27 class Scheduler { 28 static Thread itsRunningThread; 29 static Thread itsIdleThread; 30 static PriorityListOfThreads itsRunnableList; 31 32 static DEOSProcess theProcess; 34 static SynchObject synch; 35 36 public static DEOSProcess currentProcess () { 37 return theProcess; 38 } 39 40 public static Thread currentThread () { 41 return itsRunningThread; 42 } 43 44 public static Thread idleThread () { 45 return itsIdleThread; 46 } 47 48 public static void initialize () { 49 synch = new SynchObject(); 51 52 53 itsRunnableList = new PriorityListOfThreads(); 55 initializeIdleProcess(); 56 57 int interruptState = CPU.enterCritical(); 58 itsRunningThread = itsIdleThread; 59 itsRunningThread.startChargingCPUTime(); 60 CPU.exitCritical(interruptState); 61 theProcess = new DEOSProcess(); 62 DEOSKernel.localStartThread(theProcess.mainThread(), 63 Registry.uSecsInFastestPeriod, 0); 64 } 65 66 public static int priorityForPeriodIndex (int thePeriodIndex) { 67 return Registry.numPeriods - thePeriodIndex; 68 } 69 70 public static PriorityListOfThreads runnableList () { 71 return itsRunnableList; 72 } 73 74 public static void scheduleAnyThread () { 75 if (!itsRunnableList.isEmpty()) { 78 if (itsRunningThread.currentPriority() < itsRunnableList.head().parent() 79 .currentPriority()) { 80 itsRunnableList.addAtBeginning(itsRunningThread.preemptionNode); 82 Scheduler.scheduleOtherThread(); 83 } else { 84 itsRunningThread.stopChargingCPUTime(0); 86 itsRunningThread.startChargingCPUTime(); 87 } 88 } else { 89 System.out.println("How can this be!!!"); 90 } 91 } 92 93 public static void scheduleOtherThread () { 94 Thread newThread; 95 Thread fromThread = itsRunningThread; 96 97 threadListNode runnableThreadListNode = itsRunnableList.head(); 100 Thread runnableThread = runnableThreadListNode.parent(); 101 newThread = runnableThread; 102 runnableThreadListNode.removeFromList(); 103 104 105 fromThread.stopChargingCPUTime(0); 107 108 109 newThread.startChargingCPUTime(); 112 113 itsRunningThread = newThread; 121 122 } 133 134 static void handleSystemTickInterrupt () { 136 StartOfPeriodEvent.eventForPeriodIndex(0).pulseEvent(0); 138 Scheduler.scheduleAnyThread(); 139 140 } 142 143 static void handleTimerInterrupt () { 145 itsRunningThread.cpuAllowanceExceeded(); 147 } 148 149 private static void idleThreadMain () { 150 while (true) { 151 } 152 } 153 154 private static void initializeIdleProcess () { 155 itsIdleThread = new Thread ("idle"); 157 158 159 itsIdleThread.ConceptualObjectConstructor(0); 161 itsIdleThread.setCurrentPriority(0); 162 itsIdleThread.waitForNextTriggeringEvent(); 163 164 itsIdleThread.startOfPeriodWaitNode.removeFromList(); 165 166 167 itsIdleThread.setCPUBudget(Registry.periodDurationInMicroSecs( 169 itsIdleThread.periodIndex())); 170 itsIdleThread.budget().replenish(); 171 } 172 } | Popular Tags |