| 1212 | } |
| 1213 | |
| 1214 | static void runLoop(Sim2* self) { |
| 1215 | ISimulator::ProcessInfo* callingMachine = self->currentProcess; |
| 1216 | while (!self->isStopped) { |
| 1217 | self->mutex.enter(); |
| 1218 | if (self->tasks.size() == 0) { |
| 1219 | self->mutex.leave(); |
| 1220 | ASSERT(false); |
| 1221 | } |
| 1222 | // if (!randLog/* && now() >= 32.0*/) |
| 1223 | // randLog = fopen("randLog.txt", "wt"); |
| 1224 | Task t = std::move(self->tasks.top()); // Unfortunately still a copy under gcc where .top() returns const& |
| 1225 | self->currentTaskID = t.taskID; |
| 1226 | self->tasks.pop(); |
| 1227 | self->mutex.leave(); |
| 1228 | |
| 1229 | self->execTask(t); |
| 1230 | self->yielded = false; |
| 1231 | } |
| 1232 | self->currentProcess = callingMachine; |
| 1233 | for (auto& fn : self->stopCallbacks) { |
| 1234 | fn(); |
| 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | // Implement ISimulator interface |
| 1239 | void run() override { runLoop(this); } |