add multi-thread simulator for multi-core version codes. Also add two new files in...
[IRC.git] / Robust / src / Analysis / Scheduling / Schedule.java
1 package Analysis.Scheduling;
2
3 import java.util.Hashtable;
4 import java.util.LinkedList;
5 import java.util.Queue;
6 import java.util.Vector;
7
8 import Analysis.TaskStateAnalysis.FlagState;
9 import IR.TaskDescriptor;
10
11 /** This class holds flag transition diagram(s) can be put on one core.
12  */
13 public class Schedule {
14     private int coreNum;
15     private Vector<TaskDescriptor> tasks;
16     private Hashtable<FlagState, Queue<Integer>> targetCores;
17     private Hashtable<FlagState, FlagState> targetFState;
18     private Vector<Integer> ancestorCores;
19     private Vector<Integer> childCores;
20     
21     public Schedule(int coreNum) {
22         super();
23         this.coreNum = coreNum;
24         this.tasks = null;
25         this.targetCores = null;
26         this.targetFState = null;
27         this.ancestorCores = null;
28     }
29
30     public int getCoreNum() {
31         return coreNum;
32     }
33     
34     public Hashtable<FlagState, Queue<Integer>> getTargetCoreTable() {
35         return targetCores;
36     }
37     
38     public Queue<Integer> getTargetCores(FlagState fstate) {
39         if(targetCores == null) {
40             return null;
41         }
42         return targetCores.get(fstate);
43     }
44     
45     public Hashtable<FlagState, FlagState> getTargetFStateTable() {
46         return targetFState;
47     }
48     
49     public FlagState getTargetFState(FlagState fstate) {
50         if(targetFState == null) {
51             return null;
52         }
53         return targetFState.get(fstate);
54     }
55
56     public void addTargetCore(FlagState fstate, Integer targetCore/*, Integer num*/) {
57         if(this.targetCores == null) {
58             this.targetCores = new Hashtable<FlagState, Queue<Integer>>();
59         }
60         if(!this.targetCores.containsKey(fstate)) {
61             this.targetCores.put(fstate, new LinkedList<Integer>());
62         }
63         //if(!this.targetCores.get(fstate).contains(targetCore)) {
64             this.targetCores.get(fstate).add(targetCore); // there may have some duplicate items,
65                                                           // which reflects probabilities.
66         //}
67     }
68     
69     public void addTargetCore(FlagState fstate, Integer targetCore, FlagState tfstate) {
70         if(this.targetCores == null) {
71             this.targetCores = new Hashtable<FlagState, Queue<Integer>>();
72         }
73         if(!this.targetCores.containsKey(fstate)) {
74             this.targetCores.put(fstate, new LinkedList<Integer>());
75         }
76         //if(!this.targetCores.get(fstate).contains(targetCore)) {
77             this.targetCores.get(fstate).add(targetCore);
78         //}
79         if(this.targetFState == null) {
80             this.targetFState = new Hashtable<FlagState, FlagState>();
81         }
82         //if(!this.targetFState.containsKey(fstate)) {
83             this.targetFState.put(fstate, tfstate);
84         //}
85     }
86
87     public Vector<TaskDescriptor> getTasks() {
88         return tasks;
89     }
90
91     public void addTask(TaskDescriptor task) {
92         if(this.tasks == null) {
93             this.tasks = new Vector<TaskDescriptor>();
94         }
95         if(!this.tasks.contains(task)) {
96             this.tasks.add(task);
97         }
98     }
99
100     public Vector<Integer> getAncestorCores() {
101         return ancestorCores;
102     }
103
104     public void setAncestorCores(Vector<Integer> ancestorCores) {
105         this.ancestorCores = ancestorCores;
106     }
107
108     public void addAncestorCores(Integer ancestorCore) {
109         if(this.ancestorCores == null) {
110             this.ancestorCores = new Vector<Integer>();
111         }
112         if((ancestorCore.intValue() != this.coreNum) && (!this.ancestorCores.contains(ancestorCore))) {
113             this.ancestorCores.addElement(ancestorCore);
114         }
115     }
116     
117     public int ancestorCoresNum() {
118         if(this.ancestorCores == null) {
119             return 0;
120         }
121         return this.ancestorCores.size();
122     }
123
124     public Vector<Integer> getChildCores() {
125         return childCores;
126     }
127
128     public void setChildCores(Vector<Integer> childCores) {
129         this.childCores = childCores;
130     }
131     
132     public void addChildCores(Integer childCore) {
133         if(this.childCores == null) {
134             this.childCores = new Vector<Integer>();
135         }
136         if((childCore.intValue() != this.coreNum) && (!this.childCores.contains(childCore))) {
137             this.childCores.addElement(childCore);
138         }
139     }
140     
141     public int childCoresNum() {
142         if(this.childCores == null) {
143             return 0;
144         }
145         return this.childCores.size();
146     }
147     
148 }