process.cc (12997:cfc14d8f4725) process.cc (12998:68d2c7538b82)
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

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

27 * Authors: Gabe Black
28 */
29
30#include "systemc/core/process.hh"
31
32#include "base/logging.hh"
33#include "systemc/core/event.hh"
34#include "systemc/core/scheduler.hh"
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

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

27 * Authors: Gabe Black
28 */
29
30#include "systemc/core/process.hh"
31
32#include "base/logging.hh"
33#include "systemc/core/event.hh"
34#include "systemc/core/scheduler.hh"
35#include "systemc/ext/core/sc_process_handle.hh"
36#include "systemc/ext/utils/sc_report_handler.hh"
35
36namespace sc_gem5
37{
38
39SensitivityTimeout::SensitivityTimeout(Process *p, ::sc_core::sc_time t) :
40 Sensitivity(p), timeoutEvent(this), time(t)
41{
42 Tick when = scheduler.getCurTick() + time.value();

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

196 if (inc_kids)
197 forEachKid([](Process *p) { p->kill(true); });
198
199 // If we're in the middle of unwinding, ignore the kill request.
200 if (_isUnwinding)
201 return;
202
203 // Update our state.
37
38namespace sc_gem5
39{
40
41SensitivityTimeout::SensitivityTimeout(Process *p, ::sc_core::sc_time t) :
42 Sensitivity(p), timeoutEvent(this), time(t)
43{
44 Tick when = scheduler.getCurTick() + time.value();

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

198 if (inc_kids)
199 forEachKid([](Process *p) { p->kill(true); });
200
201 // If we're in the middle of unwinding, ignore the kill request.
202 if (_isUnwinding)
203 return;
204
205 // Update our state.
204 _terminated = true;
206 terminate();
205 _isUnwinding = true;
207 _isUnwinding = true;
206 _suspendedReady = false;
207 _suspended = false;
208 _syncReset = false;
209
208
210 // Inject the kill exception into this process.
211 injectException(killException);
209 // Make sure this process isn't marked ready
210 popListNode();
212
211
212 // Inject the kill exception into this process if it's started.
213 if (!_needsStart)
214 injectException(killException);
215
213 _terminatedEvent.notify();
214}
215
216void
217Process::reset(bool inc_kids)
218{
219 // Propogate the reset to our children no matter what happens to us.
220 if (inc_kids)
221 forEachKid([](Process *p) { p->reset(true); });
222
223 // If we're in the middle of unwinding, ignore the reset request.
224 if (_isUnwinding)
225 return;
226
216 _terminatedEvent.notify();
217}
218
219void
220Process::reset(bool inc_kids)
221{
222 // Propogate the reset to our children no matter what happens to us.
223 if (inc_kids)
224 forEachKid([](Process *p) { p->reset(true); });
225
226 // If we're in the middle of unwinding, ignore the reset request.
227 if (_isUnwinding)
228 return;
229
227 // Update our state.
228 _isUnwinding = true;
229
230
230 // Inject the reset exception into this process.
231 injectException(resetException);
231 if (_needsStart) {
232 scheduler.runNow(this);
233 } else {
234 _isUnwinding = true;
235 injectException(resetException);
236 }
232
233 _resetEvent.notify();
234}
235
236void
237Process::throw_it(ExceptionWrapperBase &exc, bool inc_kids)
238{
239 if (inc_kids)
240 forEachKid([&exc](Process *p) { p->throw_it(exc, true); });
237
238 _resetEvent.notify();
239}
240
241void
242Process::throw_it(ExceptionWrapperBase &exc, bool inc_kids)
243{
244 if (inc_kids)
245 forEachKid([&exc](Process *p) { p->throw_it(exc, true); });
246
247 // Only inject an exception into threads that have started.
248 if (!_needsStart)
249 injectException(exc);
241}
242
243void
244Process::injectException(ExceptionWrapperBase &exc)
245{
246 excWrapper = &exc;
247 scheduler.runNow(this);
248};

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

290 reset = false;
291 try {
292 func->call();
293 } catch(const ::sc_core::sc_unwind_exception &exc) {
294 reset = exc.is_reset();
295 _isUnwinding = false;
296 }
297 } while (reset);
250}
251
252void
253Process::injectException(ExceptionWrapperBase &exc)
254{
255 excWrapper = &exc;
256 scheduler.runNow(this);
257};

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

299 reset = false;
300 try {
301 func->call();
302 } catch(const ::sc_core::sc_unwind_exception &exc) {
303 reset = exc.is_reset();
304 _isUnwinding = false;
305 }
306 } while (reset);
298 _terminated = true;
299}
300
301void
302Process::addStatic(PendingSensitivity *s)
303{
304 pendingStaticSensitivities.push_back(s);
305}
306

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

341 new ::sc_core::sc_report(*report));
342 } else {
343 _lastReport = nullptr;
344 }
345}
346
347::sc_core::sc_report *Process::lastReport() const { return _lastReport.get(); }
348
307}
308
309void
310Process::addStatic(PendingSensitivity *s)
311{
312 pendingStaticSensitivities.push_back(s);
313}
314

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

349 new ::sc_core::sc_report(*report));
350 } else {
351 _lastReport = nullptr;
352 }
353}
354
355::sc_core::sc_report *Process::lastReport() const { return _lastReport.get(); }
356
349Process::Process(const char *name, ProcessFuncWrapper *func,
350 bool _dynamic, bool needs_start) :
357Process::Process(const char *name, ProcessFuncWrapper *func, bool _dynamic) :
351 ::sc_core::sc_object(name), excWrapper(nullptr), func(func),
358 ::sc_core::sc_object(name), excWrapper(nullptr), func(func),
352 _needsStart(needs_start), _dynamic(_dynamic), _isUnwinding(false),
359 _needsStart(true), _dynamic(_dynamic), _isUnwinding(false),
353 _terminated(false), _suspended(false), _disabled(false),
354 _syncReset(false), refCount(0), stackSize(::Fiber::DefaultStackSize),
355 dynamicSensitivity(nullptr)
356{
357 _newest = this;
358}
359
360 _terminated(false), _suspended(false), _disabled(false),
361 _syncReset(false), refCount(0), stackSize(::Fiber::DefaultStackSize),
362 dynamicSensitivity(nullptr)
363{
364 _newest = this;
365}
366
367void
368Process::terminate()
369{
370 _terminated = true;
371 _suspendedReady = false;
372 _suspended = false;
373 _syncReset = false;
374 delete dynamicSensitivity;
375 dynamicSensitivity = nullptr;
376 for (auto s: staticSensitivities)
377 delete s;
378 staticSensitivities.clear();
379}
380
360Process *Process::_newest;
361
362void
363throw_it_wrapper(Process *p, ExceptionWrapperBase &exc, bool inc_kids)
364{
365 p->throw_it(exc, inc_kids);
366}
367
368} // namespace sc_gem5
381Process *Process::_newest;
382
383void
384throw_it_wrapper(Process *p, ExceptionWrapperBase &exc, bool inc_kids)
385{
386 p->throw_it(exc, inc_kids);
387}
388
389} // namespace sc_gem5