sim: Split ClockedObject to make it usable to non-SimObjects
authorAndreas Sandberg <andreas.sandberg@arm.com>
Fri, 7 Aug 2015 08:59:22 +0000 (09:59 +0100)
committerAndreas Sandberg <andreas.sandberg@arm.com>
Fri, 7 Aug 2015 08:59:22 +0000 (09:59 +0100)
Split ClockedObject into two classes: Clocked that provides the basic
clock functionality, and ClockedObject that inherits from Clocked and
SimObject to provide the functionality of the old ClockedObject.

src/sim/clock_domain.hh
src/sim/clocked_object.hh

index c4242af55fde0ef4d102d942d6af64ad478ac505..e0dce973b6aa2c4be032a76dfed6f5f28147cd5e 100644 (file)
@@ -62,7 +62,7 @@
  */
 class DerivedClockDomain;
 class VoltageDomain;
-class ClockedObject;
+class Clocked;
 
 /**
  * The ClockDomain provides clock to group of clocked objects bundled
@@ -103,7 +103,7 @@ class ClockDomain : public SimObject
      * Pointers to members of this clock domain, so that when the clock
      * period changes, we can update each member's tick.
      */
-    std::vector<ClockedObject*> members;
+    std::vector<Clocked *> members;
 
   public:
 
@@ -123,11 +123,11 @@ class ClockDomain : public SimObject
     Tick clockPeriod() const { return _clockPeriod; }
 
     /**
-     * Register a ClockedObject to this ClockDomain.
+     * Register a Clocked object with this ClockDomain.
      *
-     * @param ClockedObject to add as a member
+     * @param Clocked to add as a member
      */
-    void registerWithClockDomain(ClockedObject *c)
+    void registerWithClockDomain(Clocked *c)
     {
         assert(c != NULL);
         assert(std::find(members.begin(), members.end(), c) == members.end());
index d878f4704b274bfb3d2a34297a75a56987d8ae06..e064d7a32ee14d67e28c2f9f2bca65376040905d 100644 (file)
 #include "sim/sim_object.hh"
 
 /**
- * The ClockedObject class extends the SimObject with a clock and
- * accessor functions to relate ticks to the cycles of the object.
+ * Helper class for objects that need to be clocked. Clocked objects
+ * typically inherit from this class. Objects that need SimObject
+ * functionality as well should inherit from ClockedObject.
  */
-class ClockedObject : public SimObject
+class Clocked
 {
 
   private:
-
     // the tick value of the next clock edge (>= curTick()) at the
     // time of the last call to update()
     mutable Tick tick;
@@ -71,13 +71,6 @@ class ClockedObject : public SimObject
     // 'tick'
     mutable Cycles cycle;
 
-    /**
-     * Prevent inadvertent use of the copy constructor and assignment
-     * operator by making them private.
-     */
-    ClockedObject(ClockedObject&);
-    ClockedObject& operator=(ClockedObject&);
-
     /**
      *  Align cycle and tick to the next clock edge if not already done. When
      *  complete, tick must be at least curTick().
@@ -118,18 +111,21 @@ class ClockedObject : public SimObject
      * Create a clocked object and set the clock domain based on the
      * parameters.
      */
-    ClockedObject(const ClockedObjectParams* p) :
-        SimObject(p), tick(0), cycle(0), clockDomain(*p->clk_domain)
+    Clocked(ClockDomain &clk_domain)
+        : tick(0), cycle(0), clockDomain(clk_domain)
     {
         // Register with the clock domain, so that if the clock domain
         // frequency changes, we can update this object's tick.
         clockDomain.registerWithClockDomain(this);
     }
 
+    Clocked(Clocked &) = delete;
+    Clocked &operator=(Clocked &) = delete;
+
     /**
      * Virtual destructor due to inheritance.
      */
-    virtual ~ClockedObject() { }
+    virtual ~Clocked() { }
 
     /**
      * Reset the object's clock using the current global tick value. Likely
@@ -221,4 +217,16 @@ class ClockedObject : public SimObject
 
 };
 
+/**
+ * The ClockedObject class extends the SimObject with a clock and
+ * accessor functions to relate ticks to the cycles of the object.
+ */
+class ClockedObject
+    : public SimObject, public Clocked
+{
+  public:
+    ClockedObject(const ClockedObjectParams *p)
+        : SimObject(p), Clocked(*p->clk_domain) { }
+};
+
 #endif //__SIM_CLOCKED_OBJECT_HH__