1 package DEOS; 20 21 24 class DEOSProcess { 25 static ProcessConstraint itsProcessConstraint; 26 static Thread itsMainThread; 27 int cpuUtilization = Registry.uSecsInFastestPeriod; 28 29 public DEOSProcess () { 30 itsMainThread = new Thread ("main"); 32 itsMainThread.setCPUBudget(Registry.uSecsInFastestPeriod); 33 itsMainThread.ConceptualObjectConstructor(0); 34 itsProcessConstraint = new ProcessConstraint(cpuUtilization); 35 } 36 37 public static int allocateCPUBudgetForThread (Thread theThread, 42 int requestedBudget, 43 int periodIndex) { 44 int grantedCPU; 46 47 if (theThread == itsMainThread) { 48 return itsMainThread.cpuBudget(); 49 } 50 51 boolean result = itsProcessConstraint.allocateCPUForThread(requestedBudget, 52 periodIndex, 53 false 54 ); 55 56 if (result) { 57 itsMainThread.setCPUBudget(itsMainThread.cpuBudget() - 58 ProcessConstraint.CPUTimeToNormalizedUtilization( 59 requestedBudget, periodIndex)); 60 grantedCPU = requestedBudget; 61 } else { 62 grantedCPU = -1; 63 } 64 65 return grantedCPU; 66 } 67 68 public static void deallocateCPUBudgetForThread (Thread theThread) { 69 int budget = theThread.cpuBudget(); 70 int periodIndex = theThread.periodIndex(); 71 itsProcessConstraint.deallocateCPUForThread(budget, periodIndex); 72 itsMainThread.setCPUBudget(itsMainThread.cpuBudget() + 73 ProcessConstraint.CPUTimeToNormalizedUtilization( 74 budget, periodIndex)); 75 } 76 77 public static Thread mainThread () { 78 return itsMainThread; 79 } 80 } | Popular Tags |