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 --- 26 unchanged lines hidden (view full) --- 35#include "systemc/ext/core/sc_join.hh" 36#include "systemc/ext/core/sc_main.hh" 37#include "systemc/ext/core/sc_process_handle.hh" 38#include "systemc/ext/utils/sc_report_handler.hh" 39 40namespace sc_gem5 41{ 42 |
43class UnwindExceptionReset : public ::sc_core::sc_unwind_exception 44{ 45 public: 46 UnwindExceptionReset() { _isReset = true; } 47}; 48 49class UnwindExceptionKill : public ::sc_core::sc_unwind_exception 50{ --- 60 unchanged lines hidden (view full) --- 111 112void 113Process::disable(bool inc_kids) 114{ 115 if (inc_kids) 116 forEachKid([](Process *p) { p->disable(true); }); 117 118 if (!::sc_core::sc_allow_process_control_corners && |
119 timeoutEvent.scheduled()) { |
120 std::string message("attempt to disable a thread with timeout wait: "); 121 message += name(); 122 SC_REPORT_ERROR("Undefined process control interaction", 123 message.c_str()); 124 } 125 126 _disabled = true; 127} --- 105 unchanged lines hidden (view full) --- 233 forEachKid([](Process *p) { p->syncResetOff(true); }); 234 235 _syncReset = false; 236} 237 238void 239Process::finalize() 240{ |
241 for (auto s: staticSensitivities) 242 s->finalize(); |
243}; 244 245void 246Process::run() 247{ 248 bool reset; 249 do { 250 reset = false; --- 7 unchanged lines hidden (view full) --- 258 } catch (...) { 259 throw; 260 } 261 } while (reset); 262 needsStart(true); 263} 264 265void |
266Process::addStatic(StaticSensitivity *s) |
267{ |
268 staticSensitivities.push_back(s); |
269} 270 271void |
272Process::setDynamic(DynamicSensitivity *s) |
273{ |
274 if (dynamicSensitivity) { 275 dynamicSensitivity->clear(); 276 delete dynamicSensitivity; 277 } |
278 dynamicSensitivity = s; |
279 if (dynamicSensitivity) 280 dynamicSensitivity->finalize(); |
281} 282 283void |
284Process::cancelTimeout() 285{ 286 if (timeoutEvent.scheduled()) 287 scheduler.deschedule(&timeoutEvent); 288} 289 290void 291Process::setTimeout(::sc_core::sc_time t) 292{ 293 cancelTimeout(); 294 scheduler.schedule(&timeoutEvent, t); 295} 296 297void 298Process::timeout() 299{ 300 // A process is considered timed_out only if it was also waiting for an 301 // event but got a timeout instead. 302 _timedOut = (dynamicSensitivity != nullptr); 303 304 setDynamic(nullptr); 305 if (disabled()) 306 return; 307 308 ready(); 309} 310 311void |
312Process::satisfySensitivity(Sensitivity *s) 313{ 314 // If there's a dynamic sensitivity and this wasn't it, ignore. |
315 if ((dynamicSensitivity || timeoutEvent.scheduled()) && 316 dynamicSensitivity != s) { |
317 return; |
318 } |
319 |
320 _timedOut = false; 321 // This sensitivity should already be cleared by this point, or the event 322 // which triggered it will take care of it. 323 delete dynamicSensitivity; 324 dynamicSensitivity = nullptr; 325 cancelTimeout(); |
326 ready(); 327} 328 329void 330Process::ready() 331{ 332 if (disabled()) 333 return; --- 12 unchanged lines hidden (view full) --- 346 } else { 347 _lastReport = nullptr; 348 } 349} 350 351::sc_core::sc_report *Process::lastReport() const { return _lastReport.get(); } 352 353Process::Process(const char *name, ProcessFuncWrapper *func, bool internal) : |
354 ::sc_core::sc_process_b(name), excWrapper(nullptr), 355 timeoutEvent([this]() { this->timeout(); }), 356 func(func), _internal(internal), _timedOut(false), _dontInitialize(false), |
357 _needsStart(true), _isUnwinding(false), _terminated(false), 358 _suspended(false), _disabled(false), _syncReset(false), refCount(0), 359 stackSize(::Fiber::DefaultStackSize), dynamicSensitivity(nullptr) 360{ 361 _dynamic = 362 (::sc_core::sc_get_status() > 363 ::sc_core::SC_BEFORE_END_OF_ELABORATION); 364 _newest = this; 365} 366 367void 368Process::terminate() 369{ 370 _terminated = true; 371 _suspendedReady = false; 372 _suspended = false; 373 _syncReset = false; |
374 clearDynamic(); 375 cancelTimeout(); 376 for (auto s: staticSensitivities) { 377 s->clear(); |
378 delete s; |
379 } |
380 staticSensitivities.clear(); 381 382 _terminatedEvent.notify(); 383 384 for (auto jw: joinWaiters) 385 jw->signal(); 386 joinWaiters.clear(); 387} 388 389Process *Process::_newest; 390 391void 392throw_it_wrapper(Process *p, ExceptionWrapperBase &exc, bool inc_kids) 393{ 394 p->throw_it(exc, inc_kids); 395} 396 397} // namespace sc_gem5 |