ruby: set: corrects csprintf() call introduced by 7d95b650c9b6
[gem5.git] / src / sim / eventq.cc
index 430c6d8abde5ff46f0053bd25d51f02c71736152..d81937a864564e5d004a4a3ab16e30d541b2d18f 100644 (file)
@@ -40,8 +40,9 @@
 #include "base/misc.hh"
 #include "base/trace.hh"
 #include "cpu/smt.hh"
+#include "debug/Config.hh"
 #include "sim/core.hh"
-#include "sim/eventq.hh"
+#include "sim/eventq_impl.hh"
 
 using namespace std;
 
@@ -200,9 +201,13 @@ EventQueue::serviceOne()
 
     // handle action
     if (!event->squashed()) {
+        // forward current cycle to the time when this event occurs.
+        setCurTick(event->when());
+
         event->process();
         if (event->isExitEvent()) {
-            assert(!event->flags.isSet(Event::AutoDelete)); // would be silly
+            assert(!event->flags.isSet(Event::AutoDelete) ||
+                   !event->flags.isSet(Event::IsMainQueue)); // would be silly
             return event;
         }
     } else {
@@ -233,13 +238,22 @@ Event::unserialize(Checkpoint *cp, const string &section)
     UNSERIALIZE_SCALAR(_when);
     UNSERIALIZE_SCALAR(_priority);
 
-    // 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)
     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)
     bool wasScheduled = flags.isSet(Scheduled) && !flags.isSet(Squashed);
     flags.clear(Squashed | Scheduled);
 
@@ -300,7 +314,7 @@ void
 EventQueue::dump() const
 {
     cprintf("============================================================\n");
-    cprintf("EventQueue Dump  (cycle %d)\n", curTick);
+    cprintf("EventQueue Dump  (cycle %d)\n", curTick());
     cprintf("------------------------------------------------------------\n");
 
     if (empty())
@@ -363,6 +377,14 @@ EventQueue::debugVerify() const
     return true;
 }
 
+Event*
+EventQueue::replaceHead(Event* s)
+{
+    Event* t = head;
+    head = s;
+    return t;
+}
+
 void
 dumpMainQueue()
 {
@@ -408,3 +430,7 @@ Event::dump() const
         cprintf("Not Scheduled\n");
     }
 }
+
+EventQueue::EventQueue(const string &n)
+    : objName(n), head(NULL), _curTick(0)
+{}