Deleted Added
sdiff udiff text old ( 13154:f86c71dac456 ) new ( 13176:76f52e8d8c6a )
full compact
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright

--- 33 unchanged lines hidden (view full) ---

42 eq(nullptr), readyEvent(this, false, ReadyPriority),
43 pauseEvent(this, false, PausePriority),
44 stopEvent(this, false, StopPriority),
45 scMain(nullptr),
46 starvationEvent(this, false, StarvationPriority),
47 _started(false), _paused(false), _stopped(false), _stopNow(false),
48 maxTickEvent(this, false, MaxTickPriority),
49 _numCycles(0), _changeStamp(0), _current(nullptr), initDone(false),
50 runOnce(false)
51{}
52
53Scheduler::~Scheduler()
54{
55 // Clear out everything that belongs to us to make sure nobody tries to
56 // clear themselves out after the scheduler goes away.
57 clear();
58}

--- 26 unchanged lines hidden (view full) ---

85 if (maxTickEvent.scheduled())
86 deschedule(&maxTickEvent);
87
88 Process *p;
89 while ((p = toFinalize.getNext()))
90 p->popListNode();
91 while ((p = initList.getNext()))
92 p->popListNode();
93 while ((p = readyList.getNext()))
94 p->popListNode();
95
96 Channel *c;
97 while ((c = updateList.getNext()))
98 c->popListNode();
99}
100
101void
102Scheduler::initPhase()

--- 54 unchanged lines hidden (view full) ---

157 // off the list of processes to be initialized/marked ready.
158 toFinalize.pushLast(p);
159 }
160}
161
162void
163Scheduler::yield()
164{
165 _current = readyList.getNext();
166 if (!_current) {
167 // There are no more processes, so return control to evaluate.
168 Fiber::primaryFiber()->run();
169 } else {
170 _current->popListNode();
171 // Switch to whatever Fiber is supposed to run this process. All
172 // Fibers which aren't running should be parked at this line.
173 _current->fiber()->run();

--- 13 unchanged lines hidden (view full) ---

187}
188
189void
190Scheduler::ready(Process *p)
191{
192 if (_stopNow)
193 return;
194
195 // Clump methods together to minimize context switching.
196 static bool cluster_methods = false;
197
198 if (cluster_methods && p->procKind() == ::sc_core::SC_METHOD_PROC_)
199 readyList.pushFirst(p);
200 else
201 readyList.pushLast(p);
202
203 scheduleReadyEvent();
204}
205
206void
207Scheduler::resume(Process *p)
208{
209 if (initDone)
210 ready(p);
211 else
212 initList.pushLast(p);
213}
214
215bool
216Scheduler::suspend(Process *p)
217{
218 if (initDone) {
219 // After initialization, the only list we can be on is the ready list.
220 bool was_ready = (p->nextListNode != nullptr);
221 p->popListNode();
222 return was_ready;
223 } else {
224 bool was_ready = false;
225 // Check the ready list to see if we find this process.
226 ListNode *n = readyList.nextListNode;
227 while (n != &readyList) {
228 if (n == p) {
229 was_ready = true;
230 break;
231 }
232 }
233 if (was_ready)
234 toFinalize.pushLast(p);
235 return was_ready;
236 }
237}
238
239void
240Scheduler::requestUpdate(Channel *c)
241{
242 updateList.pushLast(c);
243 scheduleReadyEvent();
244}

--- 17 unchanged lines hidden (view full) ---

262 if (readyEvent.scheduled())
263 deschedule(&readyEvent);
264 }
265}
266
267void
268Scheduler::runReady()
269{
270 bool empty = readyList.empty();
271 lastReadyTick = getCurTick();
272
273 // The evaluation phase.
274 do {
275 yield();
276 } while (!readyList.empty());
277
278 if (!empty) {
279 _numCycles++;
280 _changeStamp++;
281 }
282
283 if (_stopNow)
284 return;
285

--- 117 unchanged lines hidden ---