001: //
002: // Copyright (C) 2005 United States Government as represented by the
003: // Administrator of the National Aeronautics and Space Administration
004: // (NASA). All Rights Reserved.
005: //
006: // This software is distributed under the NASA Open Source Agreement
007: // (NOSA), version 1.3. The NOSA has been approved by the Open Source
008: // Initiative. See the file NOSA-1.3-JPF at the top of the distribution
009: // directory tree for the complete NOSA document.
010: //
011: // THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
012: // KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
013: // LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
014: // SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
015: // A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
016: // THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
017: // DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
018: //
019: package DEOS;
020:
021: /**
022: * DOCUMENT ME!
023: */
024: class StartOfPeriodEvent {
025: //static int[] startOfPeriodTickValues;
026: static StartOfPeriodEvent[] periodicEvents;
027: int itsPeriodId;
028: int itsPassCount;
029: int countDown;
030: int itsPeriodIndex;
031: threadList itsWaitingThreads;
032: StartOfPeriodEvent itsSuccessor;
033:
034: private StartOfPeriodEvent(int thePeriodIndex, int thePassCount) {
035: itsPassCount = thePassCount;
036: itsPeriodIndex = thePeriodIndex;
037: itsWaitingThreads = new threadList();
038:
039: countDown = 1;
040: itsPeriodId = 0;
041: itsSuccessor = null;
042: }
043:
044: public int currentPeriod() {
045: return itsPeriodId;
046: }
047:
048: //public static int[] startOfPeriodTickValueArray() {
049: // return startOfPeriodTickValues;
050: //}
051: public static StartOfPeriodEvent eventForPeriodIndex(int i) {
052: return periodicEvents[i];
053: }
054:
055: public static void initialize() {
056: //System.out.println("StartOfPeriodEvent.Initialize");
057: int numPeriods = Registry.numPeriods;
058:
059: //SPIN Registry::numberOfPeriodsSupported();
060: periodicEvents = new StartOfPeriodEvent[numPeriods];
061:
062: int ticksInLastPeriod = 1;
063:
064: for (int i = 0; i < numPeriods; i++) {
065: int ticksInThisPeriod = Registry
066: .periodDurationInSystemTicks(i);
067: periodicEvents[i] = new StartOfPeriodEvent(i,
068: ticksInThisPeriod / ticksInLastPeriod);
069:
070: if (i > 0) {
071: periodicEvents[i - 1].itsSuccessor = periodicEvents[i];
072: }
073:
074: ticksInLastPeriod = ticksInThisPeriod;
075: }
076:
077: //startOfPeriodTickValues = new int[numPeriods];
078: //for (int i=0; i<numPeriods; i++) {
079: // startOfPeriodTickValues[i] = 0;
080: //}
081: }
082:
083: public void makeThreadWait(Thread theThread) {
084: //System.out.println("StartOfPeriod(" + itsPeriodIndex +
085: // ").makeThreadWait");
086: itsWaitingThreads.addAtEnd(theThread.startOfPeriodWaitNode);
087: }
088:
089: public void pulseEvent(int systemTickCount) {
090: countDown = countDown - 1;
091:
092: //DEOS.println("StartOfPeriod.pulseEvent " + itsPeriodIndex +
093: // " countDown = " + countDown);
094: if (countDown == 0) {
095: itsPeriodId = (itsPeriodId + 1) % 2; /////!!!!!!!
096:
097: //startOfPeriodTickValues[itsPeriodIndex] = systemTickCount;
098: countDown = itsPassCount;
099: Scheduler.runnableList().mergeList(itsWaitingThreads);
100:
101: if (itsSuccessor != null) {
102: itsSuccessor.pulseEvent(systemTickCount);
103: }
104: }
105: }
106: }
|