Merge zizzer.eecs.umich.edu:/bk/m5
[gem5.git] / sim / eventq.hh
index 31bf9d6527417e4df9f4648543d53289e40c00e4..d62e7df10a7954ab561dbbf0aab797bf2dffe65c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003 The Regents of The University of Michigan
+ * Copyright (c) 2000-2004 The Regents of The University of Michigan
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -30,8 +30,8 @@
  * EventQueue interfaces
  */
 
-#ifndef __EVENTQ_HH__
-#define __EVENTQ_HH__
+#ifndef __SIM_EVENTQ_HH__
+#define __SIM_EVENTQ_HH__
 
 #include <assert.h>
 
 #include "sim/host.hh" // for Tick
 
 #include "base/fast_alloc.hh"
-#include "sim/serialize.hh"
 #include "base/trace.hh"
+#include "sim/serialize.hh"
 
 class EventQueue;      // forward declaration
 
+//////////////////////
+//
+// Main Event Queue
+//
+// Events on this queue are processed at the *beginning* of each
+// cycle, before the pipeline simulation is performed.
+//
+// defined in eventq.cc
+//
+//////////////////////
+extern EventQueue mainEventQueue;
+
+
 /*
  * An item on an event queue.  The action caused by a given
  * event is specified by deriving a subclass and overriding the
@@ -228,7 +241,7 @@ DelayFunction(Tick when, T *object)
       public:
         DelayEvent(Tick when, T *o)
             : Event(&mainEventQueue), object(o)
-            { setFlags(AutoDestroy); schedule(when); }
+            { setFlags(this->AutoDestroy); schedule(when); }
         void process() { (object->*F)(); }
         const char *description() { return "delay"; }
     };
@@ -236,6 +249,23 @@ DelayFunction(Tick when, T *object)
     new DelayEvent(when, object);
 }
 
+template <class T, void (T::* F)()>
+class EventWrapper : public Event
+{
+  private:
+    T *object;
+
+  public:
+    EventWrapper(T *obj, bool del = false, EventQueue *q = &mainEventQueue,
+                 Priority p = Default_Pri)
+        : Event(q, p), object(obj)
+    {
+        if (del)
+            setFlags(AutoDelete);
+    }
+    void process() { (object->*F)(); }
+};
+
 /*
  * Queue of events sorted in time order
  */
@@ -310,6 +340,8 @@ inline void
 Event::schedule(Tick t)
 {
     assert(!scheduled());
+    assert(t >= curTick);
+
     setFlags(Scheduled);
 #if TRACING_ON
     when_scheduled = curTick;
@@ -367,16 +399,5 @@ EventQueue::reschedule(Event *event)
 }
 
 
-//////////////////////
-//
-// Main Event Queue
-//
-// Events on this queue are processed at the *beginning* of each
-// cycle, before the pipeline simulation is performed.
-//
-// defined in eventq.cc
-//
-//////////////////////
-extern EventQueue mainEventQueue;
 
-#endif // __EVENTQ_HH__
+#endif // __SIM_EVENTQ_HH__