Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename networkLinkCreatedCallbacks into Link::onCreation and other cleanups
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 22 Dec 2015 22:17:42 +0000 (23:17 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 22 Dec 2015 22:17:42 +0000 (23:17 +0100)
src/surf/host_interface.hpp
src/surf/host_ptask_L07.cpp
src/surf/network_cm02.cpp
src/surf/network_interface.cpp
src/surf/network_interface.hpp
src/surf/plugins/energy.cpp

index c6c144d..7e1095d 100644 (file)
@@ -72,8 +72,9 @@ public:
  * @brief SURF Host interface class
  * @details An host represents a machine with a aggregation of a Cpu, a RoutingEdge and a Storage
  */
-class Host : public simgrid::surf::Resource,
-                public simgrid::surf::PropertyHolder {
+class Host :
+        public simgrid::surf::Resource,
+        public simgrid::surf::PropertyHolder {
 public:
   static simgrid::xbt::Extension<simgrid::Host, Host> EXTENSION_ID;
 
@@ -83,7 +84,7 @@ public:
   static simgrid::surf::signal<void(simgrid::surf::Host*, e_surf_resource_state_t, e_surf_resource_state_t)> onStateChange;
 
 public:
-  static void classInit();
+  static void classInit(); // must be called before the first use of that class
   /**
    * @brief Host constructor
    *
index f8e7b04..7a6c1eb 100644 (file)
@@ -326,7 +326,7 @@ Link* NetworkL07Model::createLink(const char *name,
                                         lat_initial, lat_trace,
                                         state_initial, state_trace,
                                         policy);
-  networkLinkCreatedCallbacks(link);
+  Link::onCreation(link);
   return link;
 }
 
index 7caca4b..a1ad735 100644 (file)
@@ -222,7 +222,7 @@ Link* NetworkCm02Model::createLink(const char *name,
 
   Link* link = new NetworkCm02Link(this, name, properties, p_maxminSystem, sg_bandwidth_factor * bw_initial, history,
                                             state_initial, state_trace, bw_initial, bw_trace, lat_initial, lat_trace, policy);
-  networkLinkCreatedCallbacks(link);
+  Link::onCreation(link);
   return link;
 }
 
index 34bf4fc..b4708a0 100644 (file)
@@ -87,7 +87,7 @@ Link **Link::linksList() {
 /** @brief destructor of the static data */
 void Link::linksExit() {
        for (auto kv : *links)
-               delete (kv.second);
+               (kv.second)->destroy();
        delete links;
 }
 
@@ -95,9 +95,10 @@ void Link::linksExit() {
  * Callbacks *
  *************/
 
-simgrid::surf::signal<void(simgrid::surf::Link*)> networkLinkCreatedCallbacks;
-simgrid::surf::signal<void(simgrid::surf::Link*)> networkLinkDestructedCallbacks;
-simgrid::surf::signal<void(simgrid::surf::Link*, e_surf_resource_state_t, e_surf_resource_state_t)> networkLinkStateChangedCallbacks;
+simgrid::surf::signal<void(simgrid::surf::Link*)> Link::onCreation;
+simgrid::surf::signal<void(simgrid::surf::Link*)> Link::onDestruction;
+simgrid::surf::signal<void(simgrid::surf::Link*, e_surf_resource_state_t, e_surf_resource_state_t)> Link::onStateChange;
+
 simgrid::surf::signal<void(simgrid::surf::NetworkAction*, e_surf_action_state_t, e_surf_action_state_t)> networkActionStateChangedCallbacks;
 simgrid::surf::signal<void(simgrid::surf::NetworkAction*, simgrid::surf::RoutingEdge *src, simgrid::surf::RoutingEdge *dst, double size, double rate)> networkCommunicateCallbacks;
 
@@ -217,9 +218,21 @@ Link::Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t prop
 
 }
 
-Link::~Link()
+/** @brief use destroy() instead of this destructor */
+Link::~Link() {
+       xbt_assert(currentlyDestroying_, "Don't delete Links directly. Call destroy() instead.");
+}
+/** @brief Fire the require callbacks and destroy the object
+ *
+ * Don't delete directly an Link, call l->destroy() instead.
+ */
+void Link::destroy()
 {
-  networkLinkDestructedCallbacks(this);
+       if (!currentlyDestroying_) {
+               currentlyDestroying_ = true;
+               onDestruction(this);
+               delete this;
+       }
 }
 
 bool Link::isUsed()
@@ -245,7 +258,7 @@ int Link::sharingPolicy()
 void Link::setState(e_surf_resource_state_t state){
   e_surf_resource_state_t old = Resource::getState();
   Resource::setState(state);
-  networkLinkStateChangedCallbacks(this, old, state);
+  onStateChange(this, old, state);
 }
 
 /**********
index 2226805..bd6def3 100644 (file)
@@ -33,34 +33,13 @@ class NetworkAction;
  * Callbacks *
  *************/
 
-/** @ingroup SURF_callbacks
- * @brief Callbacks handler which emits the callbacks after Link creation
- * @details Callback functions have the following signature: `void(Link*)`
- */
-XBT_PUBLIC_DATA(simgrid::surf::signal<void(simgrid::surf::Link*)>) networkLinkCreatedCallbacks;
-
-/** @ingroup SURF_callbacks
- * @brief Callbacks handler which emits the callbacks after Link destruction
- * @details Callback functions have the following signature: `void(Link*)`
- */
-XBT_PUBLIC_DATA(simgrid::surf::signal<void(simgrid::surf::Link*)>) networkLinkDestructedCallbacks;
 
-/** @ingroup SURF_callbacks
- * @brief Callbacks handler which emits the callbacks after Link State changed
- * @details Callback functions have the following signature: `void(LinkAction *action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
- */
-XBT_PUBLIC_DATA(simgrid::surf::signal<void(simgrid::surf::Link*, e_surf_resource_state_t, e_surf_resource_state_t)>) networkLinkStateChangedCallbacks;
-
-/** @ingroup SURF_callbacks
- * @brief Callbacks handler which emits the callbacks after NetworkAction State changed
- * @details Callback functions have the following signature: `void(NetworkAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
- */
+/** @brief Callback signal fired when the state of a NetworkAction changes
+ *  Signature: `void(NetworkAction *action, e_surf_action_state_t old, e_surf_action_state_t current)` */
 XBT_PUBLIC_DATA(simgrid::surf::signal<void(simgrid::surf::NetworkAction*, e_surf_action_state_t, e_surf_action_state_t)>) networkActionStateChangedCallbacks;
 
-/** @ingroup SURF_callbacks
- * @brief Callbacks handler which emits the callbacks after communication created
- * @details Callback functions have the following signature: `void(NetworkAction *action, RoutingEdge *src, RoutingEdge *dst, double size, double rate)`
- */
+/** @brief Callback signal fired when a NetworkAction is created (when a communication starts)
+ *  Signature: `void(NetworkAction *action, RoutingEdge *src, RoutingEdge *dst, double size, double rate)` */
 XBT_PUBLIC_DATA(simgrid::surf::signal<void(simgrid::surf::NetworkAction*, simgrid::surf::RoutingEdge *src, simgrid::surf::RoutingEdge *dst, double size, double rate)>) networkCommunicateCallbacks;
 
 }
@@ -188,7 +167,9 @@ public:
   * @brief SURF network link interface class
   * @details A Link represents the link between two [hosts](\ref Host)
   */
-class Link : public simgrid::surf::Resource, public simgrid::surf::PropertyHolder {
+class Link :
+               public simgrid::surf::Resource,
+               public simgrid::surf::PropertyHolder {
 public:
   /**
    * @brief Link constructor
@@ -214,8 +195,28 @@ public:
               tmgr_history_t history,
               tmgr_trace_t state_trace);
 
-  /** @brief Link destructor */
+  /* Link destruction logic */
+  /**************************/
+protected:
   ~Link();
+public:
+       void destroy(); // Must be called instead of the destructor
+private:
+       bool currentlyDestroying_ = false;
+
+public:
+  /** @brief Callback signal fired when a new Link is created.
+   *  Signature: void(Link*) */
+  static simgrid::surf::signal<void(simgrid::surf::Link*)> onCreation;
+
+  /** @brief Callback signal fired when a Link is destroyed.
+   *  Signature: void(Link*) */
+  static simgrid::surf::signal<void(simgrid::surf::Link*)> onDestruction;
+
+  /** @brief Callback signal fired when the state of a Link changes
+   *  Signature: `void(LinkAction *action, e_surf_resource_state_t oldState, e_surf_resource_state_t currentState)` */
+  static simgrid::surf::signal<void(simgrid::surf::Link*, e_surf_resource_state_t, e_surf_resource_state_t)> onStateChange;
+
 
   /** @brief Get the bandwidth in bytes per second of current Link */
   virtual double getBandwidth();
index be3fcd7..f320560 100644 (file)
@@ -196,10 +196,7 @@ double HostEnergy::getWattMaxAt(int pstate) {
   return max_power;
 }
 
-/**
- * Computes the power consumed by the host according to the current pstate and processor load
- *
- */
+/** @brief Computes the power consumed by the host according to the current pstate and processor load */
 double HostEnergy::getCurrentWattsValue(double cpu_load)
 {
        xbt_dynar_t power_range_list = power_range_watts_list;
@@ -226,11 +223,9 @@ double HostEnergy::getCurrentWattsValue(double cpu_load)
 
 double HostEnergy::getConsumedEnergy()
 {
-
        if(last_updated < surf_get_clock())
                update_consumption(host, this);
        return total_energy;
-
 }
 
 xbt_dynar_t HostEnergy::getWattsRangeList()