pseudoinst: get rid of mainEventQueue references.
[gem5.git] / src / sim / eventq.cc
index 78d6a458f22a9d0c7ffcc0ae72564eb384b93228..d460610642ecaada059896f7535109052a9297db 100644 (file)
@@ -51,12 +51,29 @@ using namespace std;
 // Events on this queue are processed at the *beginning* of each
 // cycle, before the pipeline simulation is performed.
 //
-EventQueue mainEventQueue("MainEventQueue");
+EventQueue mainEventQueue("Main Event Queue");
 
 #ifndef NDEBUG
 Counter Event::instanceCounter = 0;
 #endif
 
+Event::~Event()
+{
+    assert(!scheduled());
+    flags = 0;
+}
+
+const std::string
+Event::name() const
+{
+#ifndef NDEBUG
+    return csprintf("Event_%d", instance);
+#else
+    return csprintf("Event_%x", (uintptr_t)this);
+#endif
+}
+
+
 Event *
 Event::insertBefore(Event *event, Event *curr)
 {
@@ -167,7 +184,7 @@ EventQueue::serviceOne()
 {
     Event *event = head;
     Event *next = head->nextInBin;
-    event->clearFlags(Event::Scheduled);
+    event->flags.clear(Event::Scheduled);
 
     if (next) {
         // update the next bin pointer since it could be stale
@@ -185,14 +202,14 @@ EventQueue::serviceOne()
     if (!event->squashed()) {
         event->process();
         if (event->isExitEvent()) {
-            assert(!event->getFlags(Event::AutoDelete)); // would be silly
+            assert(!event->flags.isSet(Event::AutoDelete)); // would be silly
             return event;
         }
     } else {
-        event->clearFlags(Event::Squashed);
+        event->flags.clear(Event::Squashed);
     }
 
-    if (event->getFlags(Event::AutoDelete) && !event->scheduled())
+    if (event->flags.isSet(Event::AutoDelete) && !event->scheduled())
         delete event;
 
     return NULL;
@@ -203,28 +220,41 @@ Event::serialize(std::ostream &os)
 {
     SERIALIZE_SCALAR(_when);
     SERIALIZE_SCALAR(_priority);
-    SERIALIZE_ENUM(_flags);
+    short _flags = flags;
+    SERIALIZE_SCALAR(_flags);
 }
 
 void
 Event::unserialize(Checkpoint *cp, const string &section)
 {
     if (scheduled())
-        deschedule();
+        mainEventQueue.deschedule(this);
 
     UNSERIALIZE_SCALAR(_when);
     UNSERIALIZE_SCALAR(_priority);
 
+    short _flags;
+    UNSERIALIZE_SCALAR(_flags);
+
+    // Old checkpoints had no concept of the Initialized flag
+    // so restoring from old checkpoints always fail.
+    // Events are initialized on construction but original code 
+    // "flags = _flags" would just overwrite the initialization. 
+    // So, read in the checkpoint flags, but then set the Initialized 
+    // flag on top of it in order to avoid failures.
+    assert(initialized());
+    flags = _flags;
+    flags.set(Initialized);
+
     // need to see if original event was in a scheduled, unsquashed
     // state, but don't want to restore those flags in the current
     // object itself (since they aren't immediately true)
-    UNSERIALIZE_ENUM(_flags);
-    bool wasScheduled = (_flags & Scheduled) && !(_flags & Squashed);
-    _flags &= ~(Squashed | Scheduled);
+    bool wasScheduled = flags.isSet(Scheduled) && !flags.isSet(Squashed);
+    flags.clear(Squashed | Scheduled);
 
     if (wasScheduled) {
         DPRINTF(Config, "rescheduling at %d\n", _when);
-        schedule(_when);
+        mainEventQueue.schedule(this, _when);
     }
 }
 
@@ -239,7 +269,7 @@ EventQueue::serialize(ostream &os)
         Event *nextInBin = nextBin;
 
         while (nextInBin) {
-            if (nextInBin->getFlags(Event::AutoSerialize)) {
+            if (nextInBin->flags.isSet(Event::AutoSerialize)) {
                 eventPtrs.push_back(nextInBin);
                 paramOut(os, csprintf("event%d", numEvents++),
                          nextInBin->name());
@@ -374,7 +404,7 @@ void
 Event::dump() const
 {
     cprintf("Event %s (%s)\n", name(), description());
-    cprintf("Flags: %#x\n", _flags);
+    cprintf("Flags: %#x\n", flags);
 #ifdef EVENTQ_DEBUG
     cprintf("Created: %d\n", whenCreated);
 #endif
@@ -387,3 +417,7 @@ Event::dump() const
         cprintf("Not Scheduled\n");
     }
 }
+
+EventQueue::EventQueue(const string &n)
+    : objName(n), head(NULL)
+{}