KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DEOS > DEOSProcess


1 //
2
// Copyright (C) 2005 United States Government as represented by the
3
// Administrator of the National Aeronautics and Space Administration
4
// (NASA). All Rights Reserved.
5
//
6
// This software is distributed under the NASA Open Source Agreement
7
// (NOSA), version 1.3. The NOSA has been approved by the Open Source
8
// Initiative. See the file NOSA-1.3-JPF at the top of the distribution
9
// directory tree for the complete NOSA document.
10
//
11
// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
12
// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
13
// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
14
// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
15
// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
16
// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
17
// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
18
//
19
package DEOS;
20
21 /**
22  * DOCUMENT ME!
23  */

24 class DEOSProcess {
25   static ProcessConstraint itsProcessConstraint;
26   static Thread JavaDoc itsMainThread;
27   int cpuUtilization = Registry.uSecsInFastestPeriod;
28
29   public DEOSProcess () {
30     //System.out.println("Process Constructor");
31
itsMainThread = new Thread JavaDoc("main");
32     itsMainThread.setCPUBudget(Registry.uSecsInFastestPeriod);
33     itsMainThread.ConceptualObjectConstructor(0);
34     itsProcessConstraint = new ProcessConstraint(cpuUtilization);
35   }
36
37   // note - had to change this code because you can't pass an integer
38
// by reference in Java - so not, it returns -1 where it used to
39
// return false. the code in DEOSKernel.java (schedk.cpp) has also
40
// been changed to reflect this. -jp
41
public static int allocateCPUBudgetForThread (Thread JavaDoc theThread,
42                                                 int requestedBudget,
43                                                 int periodIndex) {
44     //System.out.println("Process.allocateCPUBudgetForThread");
45
int grantedCPU;
46
47     if (theThread == itsMainThread) {
48       return itsMainThread.cpuBudget();
49     }
50
51     boolean result = itsProcessConstraint.allocateCPUForThread(requestedBudget,
52                                                                periodIndex,
53                                                                false/*SPIN isAssociatedWithInterrupt*/
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 JavaDoc 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 JavaDoc mainThread () {
78     return itsMainThread;
79   }
80 }
Popular Tags