1 package DEOS; 20 21 24 class DEOSKernel { 25 public static int threadSuccess = 0; 28 public static int threadInvalidHandle = 1; 29 public static int threadInvalidInterrupt = 2; 30 public static int threadNotDormant = 3; 31 public static int threadNotSchedulable = 4; 32 public static int threadInsufficientPrivilege = 5; 33 public static int threadNotDynamic = 6; 34 public static int threadNotStatic = 7; 35 public static int threadMaximumThreadsExceeded = 8; 36 public static int threadInsufficientRAMForStack = 9; 37 public static int threadNoSuchThread = 10; 38 public static int threadInvalidTemplate = 11; 39 public static int threadNotActive = 12; 40 public static int threadInScheduleBefore = 13; 41 public static int threadInsufficientBudget = 14; 42 public static int threadDuplicateISR = 15; 43 public static int threadInvalidFromDynamicProcess = 16; 44 public static int threadPrimaryCannotBeISR = 17; 45 46 static void coldStartKernel () { 47 StartOfPeriodEvent.initialize(); 50 51 52 Scheduler.initialize(); 55 56 } 58 59 static int createThreadK (String name, int threadTemplateId, int threadBudget, 60 int periodIndex) { 61 int returnStatus; 64 DEOSProcess currentProcess = Scheduler.currentProcess(); 65 66 Thread threadCreated = new Thread (name); 68 69 if (threadCreated == null) { 70 System.out.println("Thread could not be created"); 71 returnStatus = threadMaximumThreadsExceeded; 72 } else { 73 if (!threadCreated.ConceptualObjectConstructor(periodIndex)) { 75 threadCreated = null; 76 returnStatus = threadInsufficientRAMForStack; 77 } else { 78 int interruptState = CPU.enterCritical(); 79 returnStatus = localStartThread(threadCreated, threadBudget, 80 periodIndex); 81 CPU.exitCritical(interruptState); 82 83 if (threadSuccess == returnStatus) { 84 } else { 85 threadCreated.ConceptualObjectDestructor(); 86 threadCreated = null; 87 } 88 } 89 } 90 91 return returnStatus; 92 } 93 94 static int deleteThreadK (Thread theThread) { 95 if (theThread != Scheduler.currentThread()) { 97 System.out.println("Thread " + theThread + " no longer running delete"); 98 99 return 0; 100 } 101 102 int result; 103 int interruptState = CPU.enterCritical(); 104 105 CPU.exitCritical(interruptState); 106 theThread.initiateStopAndDelete(); 107 result = threadSuccess; 108 interruptState = CPU.enterCritical(); 109 CPU.exitCritical(interruptState); 110 111 return result; 112 } 113 114 static int localStartThread (Thread theThread, int requestedThreadBudget, 115 int periodIndex) { 116 int budget; 120 121 budget = Scheduler.currentProcess() 123 .allocateCPUBudgetForThread(theThread, 124 requestedThreadBudget, 125 periodIndex); 126 127 if (budget > -1) { 128 theThread.startThread(budget); 129 130 return threadSuccess; 131 } else { 132 return threadNotSchedulable; 133 } 134 } 135 136 static int waitUntilNextPeriodK (Thread th) { 137 if (th != Scheduler.currentThread()) { 139 System.out.println("Thread " + th + " no longer running"); 140 141 return 0; 142 } 143 144 145 Scheduler.currentThread().waitForNextPeriod(); 147 148 return 0; } 150 151 } | Popular Tags |