Removed unecessary constructor call at each return.
[gem5.git] / sim / eventq.hh
index 475c4facedce0192dd16e6ae032af9d9b1b7bd4c..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
  * process() member function.
  */
-class Event : public Serializeable, public FastAlloc
+class Event : public Serializable, public FastAlloc
 {
     friend class EventQueue;
 
@@ -97,11 +110,52 @@ class Event : public Serializeable, public FastAlloc
 
   public:
 
+    /// Event priorities, to provide tie-breakers for events scheduled
+    /// at the same cycle.  Most events are scheduled at the default
+    /// priority; these values are used to control events that need to
+    /// be ordered within a cycle.
+    enum Priority {
+        /// Breakpoints should happen before anything else, so we
+        /// don't miss any action when debugging.
+        Debug_Break_Pri                = -100,
+
+        /// For some reason "delayed" inter-cluster writebacks are
+        /// scheduled before regular writebacks (which have default
+        /// priority).  Steve?
+        Delayed_Writeback_Pri  =   -1,
+
+        /// Default is zero for historical reasons.
+        Default_Pri            =    0,
+
+        /// CPU switches schedule the new CPU's tick event for the
+        /// same cycle (after unscheduling the old CPU's tick event).
+        /// The switch needs to come before any tick events to make
+        /// sure we don't tick both CPUs in the same cycle.
+        CPU_Switch_Pri         =   31,
+
+        /// Serailization needs to occur before tick events also, so
+        /// that a serialize/unserialize is identical to an on-line
+        /// CPU switch.
+        Serialize_Pri          =   32,
+
+        /// CPU ticks must come after other associated CPU events
+        /// (such as writebacks).
+        CPU_Tick_Pri           =   50,
+
+        /// Statistics events (dump, reset, etc.) come after
+        /// everything else, but before exit.
+        Stat_Event_Pri         =   90,
+
+        /// If we want to exit on this cycle, it's the very last thing
+        /// we do.
+        Sim_Exit_Pri           =  100
+    };
+
     /*
      * Event constructor
      * @param queue that the event gets scheduled on
      */
-    Event(EventQueue *q, int p = 0)
+    Event(EventQueue *q, Priority p = Default_Pri)
         : queue(q), next(NULL), _priority(p), _flags(None),
 #if TRACING_ON
           when_created(curTick), when_scheduled(0),
@@ -112,7 +166,7 @@ class Event : public Serializeable, public FastAlloc
 
     ~Event() {}
 
-    virtual std::string name() const {
+    virtual const std::string name() const {
         return csprintf("Event_%x", (uintptr_t)this);
     }
 
@@ -122,15 +176,9 @@ class Event : public Serializeable, public FastAlloc
     /// Schedule the event with the current priority or default priority
     void schedule(Tick t);
 
-    /// Schedule the event with a specific priority
-    void schedule(Tick t, int priority);
-
     /// Reschedule the event with the current priority
     void reschedule(Tick t);
 
-    /// Reschedule the event with a specific priority
-    void reschedule(Tick t, int priority);
-
     /// Remove the event from the current schedule
     void deschedule();
 
@@ -193,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"; }
     };
@@ -201,10 +249,27 @@ 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
  */
-class EventQueue : public Serializeable
+class EventQueue : public Serializable
 {
   protected:
     std::string objName;
@@ -222,7 +287,7 @@ class EventQueue : public Serializeable
         : objName(n), head(NULL)
     {}
 
-    virtual std::string name() const { return objName; }
+    virtual const std::string name() const { return objName; }
 
     // schedule the given event on this queue
     void schedule(Event *ev);
@@ -275,6 +340,8 @@ inline void
 Event::schedule(Tick t)
 {
     assert(!scheduled());
+    assert(t >= curTick);
+
     setFlags(Scheduled);
 #if TRACING_ON
     when_scheduled = curTick;
@@ -283,13 +350,6 @@ Event::schedule(Tick t)
     queue->schedule(this);
 }
 
-inline void
-Event::schedule(Tick t, int p)
-{
-    _priority = p;
-    schedule(t);
-}
-
 inline void
 Event::deschedule()
 {
@@ -313,13 +373,6 @@ Event::reschedule(Tick t)
     queue->reschedule(this);
 }
 
-inline void
-Event::reschedule(Tick t, int p)
-{
-    _priority = p;
-    reschedule(t);
-}
-
 inline void
 EventQueue::schedule(Event *event)
 {
@@ -346,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__