summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sim/sim_events.hh5
-rw-r--r--src/sim/simulate.cc18
-rw-r--r--src/sim/simulate.hh1
3 files changed, 15 insertions, 9 deletions
diff --git a/src/sim/sim_events.hh b/src/sim/sim_events.hh
index 5be2609fd..4d001f8f0 100644
--- a/src/sim/sim_events.hh
+++ b/src/sim/sim_events.hh
@@ -71,6 +71,11 @@ class GlobalSimLoopExitEvent : public GlobalEvent
void process(); // process event
virtual const char *description() const;
+
+ virtual ~GlobalSimLoopExitEvent() {
+ // simulate()'s singleton GlobalSimLoopExitEvent is always scheduled
+ deschedule();
+ }
};
class LocalSimLoopExitEvent : public Event
diff --git a/src/sim/simulate.cc b/src/sim/simulate.cc
index 7d88dc11d..14dd00fc1 100644
--- a/src/sim/simulate.cc
+++ b/src/sim/simulate.cc
@@ -71,6 +71,14 @@ thread_loop(EventQueue *queue)
}
}
+GlobalEvent*
+getLimitEvent(void) {
+ static GlobalSimLoopExitEvent
+ simulate_limit_event(mainEventQueue[0]->getCurTick(),
+ "simulate() limit reached", 0);
+ return &simulate_limit_event;
+}
+
/** Simulate for num_cycles additional cycles. If num_cycles is -1
* (the default), do not limit simulation; some other event must
* terminate the loop. Exported to Python via SWIG.
@@ -105,8 +113,7 @@ simulate(Tick num_cycles)
else // counter would roll over or be set to MaxTick anyhow
num_cycles = MaxTick;
- GlobalEvent *limit_event = new GlobalSimLoopExitEvent(num_cycles,
- "simulate() limit reached", 0, 0);
+ getLimitEvent()->reschedule(num_cycles);
GlobalSyncEvent *quantum_event = NULL;
if (numMainEventQueues > 1) {
@@ -137,13 +144,6 @@ simulate(Tick num_cycles)
dynamic_cast<GlobalSimLoopExitEvent *>(global_event);
assert(global_exit_event != NULL);
- // if we didn't hit limit_event, delete it.
- if (global_exit_event != limit_event) {
- assert(limit_event->scheduled());
- limit_event->deschedule();
- delete limit_event;
- }
-
//! Delete the simulation quantum event.
if (quantum_event != NULL) {
quantum_event->deschedule();
diff --git a/src/sim/simulate.hh b/src/sim/simulate.hh
index 5e51c76b6..18be7ea82 100644
--- a/src/sim/simulate.hh
+++ b/src/sim/simulate.hh
@@ -33,3 +33,4 @@
#include "sim/sim_events.hh"
GlobalSimLoopExitEvent *simulate(Tick num_cycles = MaxTick);
+GlobalEvent* getLimitEvent();