1 package DEOS; 20 21 24 class Assertion { 25 static Thread [] allThreads = new Thread [4]; 27 static int[] total_time = new int[2]; 28 static int num_entries = 0; 29 30 public static void addThread (Thread t) { 31 allThreads[num_entries] = t; 33 num_entries++; 34 } 35 36 public static boolean check () { 37 total_time[0] = 0; 39 total_time[1] = 0; 40 41 Thread current; 43 44 for (int i = 0; i < num_entries; i++) { 46 current = allThreads[i]; 48 49 if (current != Scheduler.idleThread()) { 50 int cp = current.itsPeriodicEvent.currentPeriod(); 51 52 if ((current.itsLastExecution == cp) && 53 (current.itsLastCompletion != cp)) { 54 total_time[1] += current.itsCurrentBudget.remainingBudgetInUsec(); 56 57 if (current.itsPeriodIndex == 0) { 61 total_time[0] += current.itsCurrentBudget.remainingBudgetInUsec(); 62 } 63 } else if (current.itsLastExecution != cp) { 64 total_time[1] += current.itsCurrentBudget.totalBudgetInUsec(); 65 66 if (current.itsPeriodIndex == 0) { 70 total_time[0] += current.itsCurrentBudget.totalBudgetInUsec(); 71 } 72 } 73 74 if (current.itsPeriodIndex == 0) { 75 int tmp = (current.itsCurrentBudget.totalBudgetInUsec()) * (StartOfPeriodEvent.eventForPeriodIndex(1).countDown - 1); 76 total_time[1] += tmp; 77 78 } 81 } 82 } 83 84 int period_count = StartOfPeriodEvent.eventForPeriodIndex(1).countDown - 1; 86 87 int current_period = StartOfPeriodEvent.eventForPeriodIndex(1) 89 .currentPeriod(); 90 91 if (Scheduler.currentThread() != Scheduler.idleThread()) { 96 int remaining = ((Registry.uSecsInFastestPeriod * period_count) + 97 Registry.uSecsInFastestPeriod) - 98 DEOS.thePeriodicClock.getUsedTime(); 99 100 if (total_time[1] > remaining) { 103 DEOS.println("Ooops: Time wanted " + total_time[1] + " > " + 104 remaining); 105 assert false; 106 } else { 107 } 109 } 110 111 total_time[0] = 0; 112 total_time[1] = 0; 113 114 return true; 115 } 116 117 public static void removeThread (Thread t) { 118 for (int i = 0; i < num_entries; i++) { 120 if (allThreads[i] == t) { 121 for (int j = i + 1; j < num_entries; j++) { 122 allThreads[j - 1] = allThreads[j]; 123 } 124 125 num_entries--; 126 127 return; 128 } 129 } 130 } 131 } | Popular Tags |