Deleted Added
sdiff udiff text old ( 13196:4b5ab2c22743 ) new ( 13206:c944ef4abb48 )
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

--- 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
43SensitivityTimeout::SensitivityTimeout(Process *p, ::sc_core::sc_time t) :
44 Sensitivity(p), timeoutEvent([this]() { this->timeout(); })
45{
46 scheduler.schedule(&timeoutEvent, t);
47}
48
49SensitivityTimeout::~SensitivityTimeout()
50{
51 if (timeoutEvent.scheduled())
52 scheduler.deschedule(&timeoutEvent);
53}
54
55void
56SensitivityTimeout::timeout()
57{
58 notify();
59}
60
61SensitivityEvent::SensitivityEvent(
62 Process *p, const ::sc_core::sc_event *e) : Sensitivity(p), event(e)
63{
64 Event::getFromScEvent(event)->addSensitivity(this);
65}
66
67SensitivityEvent::~SensitivityEvent()
68{
69 Event::getFromScEvent(event)->delSensitivity(this);
70}
71
72SensitivityEventAndList::SensitivityEventAndList(
73 Process *p, const ::sc_core::sc_event_and_list *list) :
74 Sensitivity(p), list(list), count(0)
75{
76 for (auto e: list->events)
77 Event::getFromScEvent(e)->addSensitivity(this);
78}
79
80SensitivityEventAndList::~SensitivityEventAndList()
81{
82 for (auto e: list->events)
83 Event::getFromScEvent(e)->delSensitivity(this);
84}
85
86void
87SensitivityEventAndList::notifyWork(Event *e)
88{
89 e->delSensitivity(this);
90 count++;
91 if (count == list->events.size())
92 satisfy();
93}
94
95SensitivityEventOrList::SensitivityEventOrList(
96 Process *p, const ::sc_core::sc_event_or_list *list) :
97 Sensitivity(p), list(list)
98{
99 for (auto e: list->events)
100 Event::getFromScEvent(e)->addSensitivity(this);
101}
102
103SensitivityEventOrList::~SensitivityEventOrList()
104{
105 for (auto e: list->events)
106 Event::getFromScEvent(e)->delSensitivity(this);
107}
108
109void
110SensitivityTimeoutAndEventAndList::notifyWork(Event *e)
111{
112 if (e) {
113 // An event went off which must be part of the sc_event_and_list.
114 SensitivityEventAndList::notifyWork(e);
115 } else {
116 // There's no inciting event, so this must be a timeout.
117 satisfy(true);
118 }
119}
120
121
122class UnwindExceptionReset : public ::sc_core::sc_unwind_exception
123{
124 public:
125 UnwindExceptionReset() { _isReset = true; }
126};
127
128class UnwindExceptionKill : public ::sc_core::sc_unwind_exception
129{

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

190
191void
192Process::disable(bool inc_kids)
193{
194 if (inc_kids)
195 forEachKid([](Process *p) { p->disable(true); });
196
197 if (!::sc_core::sc_allow_process_control_corners &&
198 dynamic_cast<SensitivityTimeout *>(dynamicSensitivity)) {
199 std::string message("attempt to disable a thread with timeout wait: ");
200 message += name();
201 SC_REPORT_ERROR("Undefined process control interaction",
202 message.c_str());
203 }
204
205 _disabled = true;
206}

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

312 forEachKid([](Process *p) { p->syncResetOff(true); });
313
314 _syncReset = false;
315}
316
317void
318Process::finalize()
319{
320 for (auto &s: pendingStaticSensitivities) {
321 s->finalize(staticSensitivities);
322 delete s;
323 s = nullptr;
324 }
325 pendingStaticSensitivities.clear();
326};
327
328void
329Process::run()
330{
331 bool reset;
332 do {
333 reset = false;

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

341 } catch (...) {
342 throw;
343 }
344 } while (reset);
345 needsStart(true);
346}
347
348void
349Process::addStatic(PendingSensitivity *s)
350{
351 pendingStaticSensitivities.push_back(s);
352}
353
354void
355Process::setDynamic(Sensitivity *s)
356{
357 delete dynamicSensitivity;
358 dynamicSensitivity = s;
359}
360
361void
362Process::satisfySensitivity(Sensitivity *s)
363{
364 // If there's a dynamic sensitivity and this wasn't it, ignore.
365 if (dynamicSensitivity && dynamicSensitivity != s)
366 return;
367
368 setDynamic(nullptr);
369 ready();
370}
371
372void
373Process::ready()
374{
375 if (disabled())
376 return;

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

389 } else {
390 _lastReport = nullptr;
391 }
392}
393
394::sc_core::sc_report *Process::lastReport() const { return _lastReport.get(); }
395
396Process::Process(const char *name, ProcessFuncWrapper *func, bool internal) :
397 ::sc_core::sc_process_b(name), excWrapper(nullptr), func(func),
398 _internal(internal), _timedOut(false), _dontInitialize(false),
399 _needsStart(true), _isUnwinding(false), _terminated(false),
400 _suspended(false), _disabled(false), _syncReset(false), refCount(0),
401 stackSize(::Fiber::DefaultStackSize), dynamicSensitivity(nullptr)
402{
403 _dynamic =
404 (::sc_core::sc_get_status() >
405 ::sc_core::SC_BEFORE_END_OF_ELABORATION);
406 _newest = this;
407}
408
409void
410Process::terminate()
411{
412 _terminated = true;
413 _suspendedReady = false;
414 _suspended = false;
415 _syncReset = false;
416 delete dynamicSensitivity;
417 dynamicSensitivity = nullptr;
418 for (auto s: staticSensitivities)
419 delete s;
420 staticSensitivities.clear();
421
422 _terminatedEvent.notify();
423
424 for (auto jw: joinWaiters)
425 jw->signal();
426 joinWaiters.clear();
427}
428
429Process *Process::_newest;
430
431void
432throw_it_wrapper(Process *p, ExceptionWrapperBase &exc, bool inc_kids)
433{
434 p->throw_it(exc, inc_kids);
435}
436
437} // namespace sc_gem5