about summary refs log tree commit diff stats
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/038scheduler.cc65
1 files changed, 49 insertions, 16 deletions
diff --git a/cpp/038scheduler.cc b/cpp/038scheduler.cc
index cd07cfc5..f0f970dd 100644
--- a/cpp/038scheduler.cc
+++ b/cpp/038scheduler.cc
@@ -23,34 +23,67 @@ while (!Current_routine->completed() && ninstrs < time_slice)
 ninstrs++;
 
 //: now the rest of the scheduler is clean
+
+:(before "struct routine")
+enum routine_state {
+  RUNNING,
+  COMPLETED,
+  // End Routine States
+};
+:(before "End routine Fields")
+enum routine_state state;
+:(before "End routine Constructor")
+state = RUNNING;
+
 :(before "End Globals")
-list<routine*> Running_routines, Completed_routines;
+vector<routine*> Routines;
+size_t Current_routine_index = 0;
 size_t Scheduling_interval = 500;
 :(before "End Setup")
 Scheduling_interval = 500;
 :(replace{} "void run(recipe_number r)")
 void run(recipe_number r) {
-  Running_routines.push_back(new routine(r));
-  while (!Running_routines.empty()) {
-    Current_routine = Running_routines.front();
-    Running_routines.pop_front();
+  Routines.push_back(new routine(r));
+  Current_routine_index = 0, Current_routine = Routines[0];
+  while (!all_routines_done()) {
+    assert(Current_routine);
+    assert(Current_routine->state == RUNNING);
     trace("schedule") << current_recipe_name();
     run_current_routine(Scheduling_interval);
     if (Current_routine->completed())
-      Completed_routines.push_back(Current_routine);
-    else
-      Running_routines.push_back(Current_routine);
-    Current_routine = NULL;
+      Current_routine->state = COMPLETED;
+    // End Scheduler State Transitions
+    skip_to_next_routine();
+  }
+}
+
+:(code)
+bool all_routines_done() {
+  for (size_t i = 0; i < Routines.size(); ++i) {
+    if (Routines[i]->state == RUNNING) {
+      return false;
+    }
+  }
+  return true;
+}
+
+// skip Current_routine_index past non-RUNNING routines
+void skip_to_next_routine() {
+  assert(!Routines.empty());
+  assert(Current_routine_index < Routines.size());
+  for (size_t i = (Current_routine_index+1)%Routines.size();  i != Current_routine_index;  i = (i+1)%Routines.size()) {
+    if (Routines[i]->state == RUNNING) {
+      Current_routine_index = i;
+      Current_routine = Routines[i];
+      return;
+    }
   }
 }
 
 :(before "End Teardown")
-for (list<routine*>::iterator p = Running_routines.begin(); p != Running_routines.end(); ++p)
-  delete *p;
-Running_routines.clear();
-for (list<routine*>::iterator p = Completed_routines.begin(); p != Completed_routines.end(); ++p)
-  delete *p;
-Completed_routines.clear();
+for (size_t i = 0; i < Routines.size(); ++i)
+  delete Routines[i];
+Routines.clear();
 
 :(before "End Primitive Recipe Declarations")
 RUN,
@@ -60,7 +93,7 @@ Recipe_number["run"] = RUN;
 case RUN: {
   trace("run") << "ingredient 0 is " << current_instruction().ingredients[0].name;
   assert(!current_instruction().ingredients[0].initialized);
-  Running_routines.push_back(new routine(Recipe_number[current_instruction().ingredients[0].name]));
+  Routines.push_back(new routine(Recipe_number[current_instruction().ingredients[0].name]));
   break;
 }
 
3:08 -0800 committer Kartik K. Agaram <vc@akkartik.com> 2017-12-30 22:54:41 -0800 4174' href='/akkartik/mu/commit/subx/020elf.cc?h=hlt&id=708eae3109ca71f7a7178684aaaced7c16196559'>708eae31 ^
414d9413 ^
708eae31 ^


414d9413 ^
708eae31 ^
414d9413 ^
f1b3d7b9 ^
708eae31 ^


f1b3d7b9 ^
708eae31 ^

96b2216b ^
414d9413 ^
96b2216b ^
414d9413 ^
96b2216b ^
414d9413 ^
96b2216b ^


414d9413 ^
96b2216b ^
708eae31 ^

96b2216b ^


414d9413 ^
96b2216b ^

fd7198b2 ^
96b2216b ^


708eae31 ^
9527eda9 ^
96b2216b ^
9527eda9 ^
708eae31 ^
6602c82f ^
9527eda9 ^
630433cd ^
9527eda9 ^
a1305217 ^
6602c82f ^

708eae31 ^
f1b3d7b9 ^


a413105a ^
630433cd ^
f1b3d7b9 ^
a413105a ^
a413105a ^
f1b3d7b9 ^
9527eda9 ^
f1b3d7b9 ^

4a99a6e0 ^
f1b3d7b9 ^

a413105a ^
f1b3d7b9 ^



6362c51d ^






c442a5ad ^

f1b3d7b9 ^
708eae31 ^

9527eda9 ^
96b2216b ^
fd7198b2 ^
96b2216b ^
fd7198b2 ^
96b2216b ^



414d9413 ^
96b2216b ^



630433cd ^
96b2216b ^

414d9413 ^
4a99a6e0 ^

630433cd ^

fd7198b2 ^
630433cd ^

9527eda9 ^

665a4d70 ^
9527eda9 ^

630433cd ^
96b2216b ^


1f4d0aaf ^
fbc21293 ^
44fdc79f ^






6f6d458f ^




c88b9e31 ^

e5998f74 ^

1f4d0aaf ^
e0a0484c ^
e5998f74 ^
c442a5ad ^
e0a0484c ^
7a22a219 ^

e0a0484c ^
7a22a219 ^
e0a0484c ^

708eae31 ^



96b2216b ^



414d9413 ^


1a33d221 ^
708eae31 ^
cd23c8b6 ^
414d9413 ^





1a33d221 ^
414d9413 ^

708eae31 ^

2097401c ^
708eae31 ^


708eae31 ^
087a998e ^
a066ad7e ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199