Time: Add a mechanism to prevent M5 from running faster than real time.
[gem5.git] / src / sim / eventq.hh
index 7c814d87246c34096aeeb978f53251c6b90581ed..e28c43bb774b8630bb68d470f0dbbe6dc13d7300 100644 (file)
@@ -136,7 +136,7 @@ class Event : public Serializable, public FastAlloc
         queue = q;
 #endif
 #ifdef EVENTQ_DEBUG
-        whenScheduled = curTick;
+        whenScheduled = curTick();
 #endif
     }
 
@@ -254,7 +254,7 @@ class Event : public Serializable, public FastAlloc
         queue = NULL;
 #endif
 #ifdef EVENTQ_DEBUG
-        whenCreated = curTick;
+        whenCreated = curTick();
         whenScheduled = 0;
 #endif
     }
@@ -370,10 +370,11 @@ class EventQueue : public Serializable
     void insert(Event *event);
     void remove(Event *event);
 
+    EventQueue(const EventQueue &);
+    const EventQueue &operator=(const EventQueue &);
+
   public:
-    EventQueue(const std::string &n)
-        : objName(n), head(NULL)
-    {}
+    EventQueue(const std::string &n);
 
     virtual const std::string name() const { return objName; }
 
@@ -404,15 +405,15 @@ class EventQueue : public Serializable
         }
     }
 
-    // default: process all events up to 'now' (curTick)
-    void serviceEvents() { serviceEvents(curTick); }
+    // default: process all events up to 'now' (curTick())
+    void serviceEvents() { serviceEvents(curTick()); }
 
     // return true if no events are queued
     bool empty() const { return head == NULL; }
 
     void dump() const;
 
-    Tick nextEventTime() { return empty() ? curTick : head->when(); }
+    Tick nextEventTime() { return empty() ? curTick() : head->when(); }
 
     bool debugVerify() const;
 
@@ -440,6 +441,11 @@ class EventManager
         return eventq;
     }
 
+    operator EventQueue *() const
+    {
+        return eventq;
+    }
+
     void
     schedule(Event &event, Tick when)
     {
@@ -480,7 +486,7 @@ class EventManager
 inline void
 EventQueue::schedule(Event *event, Tick when)
 {
-    assert((UTick)when >= (UTick)curTick);
+    assert((UTick)when >= (UTick)curTick());
     assert(!event->scheduled());
     assert(event->initialized());
 
@@ -517,7 +523,7 @@ EventQueue::deschedule(Event *event)
 inline void
 EventQueue::reschedule(Event *event, Tick when, bool always)
 {
-    assert(when >= curTick);
+    assert(when >= curTick());
     assert(always || event->scheduled());
     assert(event->initialized());
 
@@ -571,6 +577,13 @@ class EventWrapper : public Event
             setFlags(AutoDelete);
     }
 
+    EventWrapper(T &obj, bool del = false, Priority p = Default_Pri)
+        : Event(p), object(&obj)
+    {
+        if (del)
+            setFlags(AutoDelete);
+    }
+
     void process() { (object->*F)(); }
 
     const std::string