KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DEOS > DEOSThread


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 import gov.nasa.jpf.jvm.Verify;
22
23
24 /**
25  * DOCUMENT ME!
26  */

27 class DEOSThread {
28   Thread JavaDoc thread; // which "Thread" object is this Thread one related to
29
boolean running = false;
30
31   // run at a time
32
boolean isMain = false;
33   boolean isIdle = false;
34   boolean firstTime = true;
35   boolean setDelete = false;
36   boolean setWaitUntilNextPeriod = false;
37
38   public DEOSThread (Thread JavaDoc th) {
39     thread = th;
40     isIdle = thread.isIdle();
41     isMain = thread.isMain();
42
43     System.out.println(thread.toString() + " created");
44   }
45
46   public void run (int tickResult) {
47     //Verify.assert(Timer.timer || Timer.tick);
48
DEOS.inc();
49
50     if (tickResult == Clock.NOTIMECHANGE) {
51       if (Verify.randomBool()) {
52         //System.out.println("Thread: " + thread + " - Depth: " + depth);
53
DEOS.println("No interrupt - Choice 0:");
54         DEOS.println(thread.toString() + " waiting until next period");
55         DEOSKernel.waitUntilNextPeriodK(thread);
56
57         //yieldCPU();
58
} else {
59         //System.out.println("Thread: " + thread + " - Depth: " + depth);
60
DEOS.println("No interrupt - Choice 1:");
61         DEOS.println(thread.toString() + " deleting");
62         DEOSKernel.deleteThreadK(thread); //deleteThread();
63
}
64     } else {
65       switch (Verify.random(2)) {
66       case 0:
67
68         //System.out.println("Thread: " + thread + " - Depth: " + depth);
69
DEOS.println("Choice 0:");
70         DEOS.println(thread.toString() + " waiting until next period");
71         DEOSKernel.waitUntilNextPeriodK(thread);
72
73         //yieldCPU();
74
break;
75
76       case 2:
77
78         //System.out.println("Thread: " + thread + " - Depth: " + depth);
79
DEOS.println("Choice 2:");
80         DEOS.println(thread.toString() + " deleting");
81         DEOSKernel.deleteThreadK(thread);
82
83         //deleteThread();
84
break;
85
86       case 1:
87
88         //System.out.println("Thread: " + thread + " - Depth: " + depth);
89
DEOS.println("Choice 1: ");
90         getInterrupted(tickResult);
91
92         break;
93       }
94     }
95   }
96
97   // Modified by ckong - June 26, 2001
98
void getInterrupted (int tickResult) {
99     if (tickResult == Clock.SYSTEMINTERRUPT) {
100       DEOS.println(thread.toString() + " interrupted by system tick");
101       DEOS.thePeriodicClock.resetUsedTime();
102       Scheduler.handleSystemTickInterrupt();
103     } else if (tickResult == Clock.TIMEOUT) {
104       DEOS.println(thread.toString() + " interrupted by timer");
105       Scheduler.handleTimerInterrupt();
106     } else {
107       DEOS.println(thread.toString() + " waiting for time to pass");
108     }
109   }
110 }
Popular Tags