KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DEOS > StartOfPeriodEvent


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 StartOfPeriodEvent {
25   //static int[] startOfPeriodTickValues;
26
static StartOfPeriodEvent[] periodicEvents;
27   int itsPeriodId;
28   int itsPassCount;
29   int countDown;
30   int itsPeriodIndex;
31   threadList itsWaitingThreads;
32   StartOfPeriodEvent itsSuccessor;
33
34   private StartOfPeriodEvent (int thePeriodIndex, int thePassCount) {
35     itsPassCount = thePassCount;
36     itsPeriodIndex = thePeriodIndex;
37     itsWaitingThreads = new threadList();
38
39     countDown = 1;
40     itsPeriodId = 0;
41     itsSuccessor = null;
42   }
43
44   public int currentPeriod () {
45     return itsPeriodId;
46   }
47
48   //public static int[] startOfPeriodTickValueArray() {
49
// return startOfPeriodTickValues;
50
//}
51
public static StartOfPeriodEvent eventForPeriodIndex (int i) {
52     return periodicEvents[i];
53   }
54
55   public static void initialize () {
56     //System.out.println("StartOfPeriodEvent.Initialize");
57
int numPeriods = Registry.numPeriods;
58
59
60     //SPIN Registry::numberOfPeriodsSupported();
61
periodicEvents = new StartOfPeriodEvent[numPeriods];
62
63     int ticksInLastPeriod = 1;
64
65     for (int i = 0; i < numPeriods; i++) {
66       int ticksInThisPeriod = Registry.periodDurationInSystemTicks(i);
67       periodicEvents[i] = new StartOfPeriodEvent(i,
68                                                  ticksInThisPeriod / ticksInLastPeriod);
69
70       if (i > 0) {
71         periodicEvents[i - 1].itsSuccessor = periodicEvents[i];
72       }
73
74       ticksInLastPeriod = ticksInThisPeriod;
75     }
76
77     //startOfPeriodTickValues = new int[numPeriods];
78
//for (int i=0; i<numPeriods; i++) {
79
// startOfPeriodTickValues[i] = 0;
80
//}
81
}
82
83   public void makeThreadWait (Thread JavaDoc theThread) {
84     //System.out.println("StartOfPeriod(" + itsPeriodIndex +
85
// ").makeThreadWait");
86
itsWaitingThreads.addAtEnd(theThread.startOfPeriodWaitNode);
87   }
88
89   public void pulseEvent (int systemTickCount) {
90     countDown = countDown - 1;
91
92     //DEOS.println("StartOfPeriod.pulseEvent " + itsPeriodIndex +
93
// " countDown = " + countDown);
94
if (countDown == 0) {
95       itsPeriodId = (itsPeriodId + 1) % 2; /////!!!!!!!
96

97
98       //startOfPeriodTickValues[itsPeriodIndex] = systemTickCount;
99
countDown = itsPassCount;
100       Scheduler.runnableList().mergeList(itsWaitingThreads);
101
102       if (itsSuccessor != null) {
103         itsSuccessor.pulseEvent(systemTickCount);
104       }
105     }
106   }
107 }
Popular Tags