process.cc (12993:977fa1dfe9b3) process.cc (12995:3421144dd03e)
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

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

103 for (auto e: list->events)
104 Event::getFromScEvent(e)->delSensitivity(this);
105}
106
107
108class UnwindExceptionReset : public ::sc_core::sc_unwind_exception
109{
110 public:
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

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

103 for (auto e: list->events)
104 Event::getFromScEvent(e)->delSensitivity(this);
105}
106
107
108class UnwindExceptionReset : public ::sc_core::sc_unwind_exception
109{
110 public:
111 const char *what() const throw() override { return "RESET"; }
112 bool is_reset() const override { return true; }
111 UnwindExceptionReset() { _isReset = true; }
113};
114
115class UnwindExceptionKill : public ::sc_core::sc_unwind_exception
116{
117 public:
112};
113
114class UnwindExceptionKill : public ::sc_core::sc_unwind_exception
115{
116 public:
118 const char *what() const throw() override { return "KILL"; }
119 bool is_reset() const override { return false; }
117 UnwindExceptionKill() {}
120};
121
122template <typename T>
123struct BuiltinExceptionWrapper : public ExceptionWrapperBase
124{
125 public:
126 T t;
127 void throw_it() override { throw t; }

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

189 forEachKid([](Process *p) { p->enable(true); });
190
191 _disabled = false;
192}
193
194void
195Process::kill(bool inc_kids)
196{
118};
119
120template <typename T>
121struct BuiltinExceptionWrapper : public ExceptionWrapperBase
122{
123 public:
124 T t;
125 void throw_it() override { throw t; }

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

187 forEachKid([](Process *p) { p->enable(true); });
188
189 _disabled = false;
190}
191
192void
193Process::kill(bool inc_kids)
194{
197 // Update our state.
198 _terminated = true;
199 _isUnwinding = true;
200
201 // Propogate the kill to our children no matter what happens to us.
202 if (inc_kids)
203 forEachKid([](Process *p) { p->kill(true); });
204
205 // If we're in the middle of unwinding, ignore the kill request.
206 if (_isUnwinding)
207 return;
208
195 // Propogate the kill to our children no matter what happens to us.
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.
204 _terminated = true;
205 _isUnwinding = true;
206 _suspendedReady = false;
207 _suspended = false;
208 _syncReset = false;
209
209 // Inject the kill exception into this process.
210 injectException(killException);
211
212 _terminatedEvent.notify();
213}
214
215void
216Process::reset(bool inc_kids)
217{
210 // Inject the kill exception into this process.
211 injectException(killException);
212
213 _terminatedEvent.notify();
214}
215
216void
217Process::reset(bool inc_kids)
218{
218 // Update our state.
219 _isUnwinding = true;
220
221 // Propogate the reset to our children no matter what happens to us.
222 if (inc_kids)
223 forEachKid([](Process *p) { p->reset(true); });
224
225 // If we're in the middle of unwinding, ignore the reset request.
226 if (_isUnwinding)
227 return;
228
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
227 // Update our state.
228 _isUnwinding = true;
229
229 // Inject the reset exception into this process.
230 injectException(resetException);
231
232 _resetEvent.notify();
233}
234
235void
236Process::throw_it(ExceptionWrapperBase &exc, bool inc_kids)
237{
238 if (inc_kids)
239 forEachKid([&exc](Process *p) { p->throw_it(exc, true); });
240}
241
242void
243Process::injectException(ExceptionWrapperBase &exc)
244{
245 excWrapper = &exc;
230 // Inject the reset exception into this process.
231 injectException(resetException);
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); });
241}
242
243void
244Process::injectException(ExceptionWrapperBase &exc)
245{
246 excWrapper = &exc;
246 // Let this process preempt us.
247 scheduler.runNow(this);
247};
248
249void
250Process::syncResetOn(bool inc_kids)
251{
252 if (inc_kids)
253 forEachKid([](Process *p) { p->syncResetOn(true); });
254

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

284void
285Process::run()
286{
287 bool reset;
288 do {
289 reset = false;
290 try {
291 func->call();
248};
249
250void
251Process::syncResetOn(bool inc_kids)
252{
253 if (inc_kids)
254 forEachKid([](Process *p) { p->syncResetOn(true); });
255

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

285void
286Process::run()
287{
288 bool reset;
289 do {
290 reset = false;
291 try {
292 func->call();
292 } catch(::sc_core::sc_unwind_exception exc) {
293 } catch(const ::sc_core::sc_unwind_exception &exc) {
293 reset = exc.is_reset();
294 reset = exc.is_reset();
295 _isUnwinding = false;
294 }
295 } while (reset);
296 _terminated = true;
297}
298
299void
300Process::addStatic(PendingSensitivity *s)
301{

--- 50 unchanged lines hidden ---
296 }
297 } while (reset);
298 _terminated = true;
299}
300
301void
302Process::addStatic(PendingSensitivity *s)
303{

--- 50 unchanged lines hidden ---