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 --- 32 unchanged lines hidden (view full) --- 41{ 42 43Scheduler::Scheduler() : 44 eq(nullptr), readyEvent(this, false, ReadyPriority), 45 pauseEvent(this, false, PausePriority), 46 stopEvent(this, false, StopPriority), 47 scMain(nullptr), _throwToScMain(nullptr), 48 starvationEvent(this, false, StarvationPriority), |
49 _started(false), _stopNow(false), _status(StatusOther), |
50 maxTickEvent(this, false, MaxTickPriority), 51 _numCycles(0), _changeStamp(0), _current(nullptr), initDone(false), 52 runOnce(false), readyList(nullptr) 53{} 54 55Scheduler::~Scheduler() 56{ 57 // Clear out everything that belongs to us to make sure nobody tries to --- 60 unchanged lines hidden (view full) --- 118 } 119 120 for (Process *p = initList.getNext(); p; p = initList.getNext()) { 121 p->finalize(); 122 p->popListNode(); 123 p->ready(); 124 } 125 |
126 runUpdate(); 127 runDelta(); |
128 |
129 for (auto ets: eventsToSchedule) 130 eq->schedule(ets.first, ets.second); 131 eventsToSchedule.clear(); 132 133 if (_started) { 134 if (!runToTime && starved()) 135 scheduleStarvationEvent(); 136 kernel->status(::sc_core::SC_RUNNING); 137 } 138 139 initDone = true; |
140 141 status(StatusOther); |
142} 143 144void 145Scheduler::reg(Process *p) 146{ 147 if (initDone) { 148 // If we're past initialization, finalize static sensitivity. 149 p->finalize(); --- 156 unchanged lines hidden (view full) --- 306 if (!empty) { 307 _numCycles++; 308 _changeStamp++; 309 } 310 311 if (_stopNow) 312 return; 313 |
314 runUpdate(); 315 runDelta(); |
316 |
317 if (!runToTime && starved()) 318 scheduleStarvationEvent(); 319 320 if (runOnce) 321 schedulePause(); |
322 323 status(StatusOther); |
324} 325 326void |
327Scheduler::runUpdate() |
328{ |
329 status(StatusUpdate); 330 |
331 Channel *channel = updateList.getNext(); 332 while (channel) { 333 channel->popListNode(); 334 channel->update(); 335 channel = updateList.getNext(); 336 } 337} 338 339void |
340Scheduler::runDelta() 341{ 342 status(StatusDelta); 343 while (!deltas.empty()) 344 deltas.front()->run(); 345} 346 347void |
348Scheduler::pause() 349{ |
350 status(StatusPaused); |
351 kernel->status(::sc_core::SC_PAUSED); 352 runOnce = false; 353 if (scMain && !scMain->finished()) 354 scMain->run(); 355} 356 357void 358Scheduler::stop() 359{ |
360 status(StatusStopped); |
361 kernel->stop(); 362 363 clear(); 364 365 runOnce = false; 366 if (scMain && !scMain->finished()) 367 scMain->run(); 368} 369 370void 371Scheduler::start(Tick max_tick, bool run_to_time) 372{ 373 // We should be running from sc_main. Keep track of that Fiber to return 374 // to later. 375 scMain = Fiber::currentFiber(); 376 377 _started = true; |
378 status(StatusOther); |
379 runToTime = run_to_time; 380 381 maxTick = max_tick; 382 lastReadyTick = getCurTick(); 383 384 if (initDone) { 385 if (!runToTime && starved()) 386 scheduleStarvationEvent(); --- 110 unchanged lines hidden --- |