From 400da29670150f252dc2b3878c230f2e1b4a0cef Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 22 Dec 2015 23:17:42 +0100 Subject: [PATCH] rename networkLinkCreatedCallbacks into Link::onCreation and other cleanups --- src/surf/host_interface.hpp | 7 +++-- src/surf/host_ptask_L07.cpp | 2 +- src/surf/network_cm02.cpp | 2 +- src/surf/network_interface.cpp | 27 ++++++++++++----- src/surf/network_interface.hpp | 55 +++++++++++++++++----------------- src/surf/plugins/energy.cpp | 7 +---- 6 files changed, 55 insertions(+), 45 deletions(-) diff --git a/src/surf/host_interface.hpp b/src/surf/host_interface.hpp index c6c144d231..7e1095d52f 100644 --- a/src/surf/host_interface.hpp +++ b/src/surf/host_interface.hpp @@ -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 EXTENSION_ID; @@ -83,7 +84,7 @@ public: static simgrid::surf::signal onStateChange; public: - static void classInit(); + static void classInit(); // must be called before the first use of that class /** * @brief Host constructor * diff --git a/src/surf/host_ptask_L07.cpp b/src/surf/host_ptask_L07.cpp index f8e7b045c9..7a6c1eb09e 100644 --- a/src/surf/host_ptask_L07.cpp +++ b/src/surf/host_ptask_L07.cpp @@ -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; } diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 7caca4b743..a1ad735e13 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -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; } diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index 34bf4fc1c9..b4708a0d5e 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -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 networkLinkCreatedCallbacks; -simgrid::surf::signal networkLinkDestructedCallbacks; -simgrid::surf::signal networkLinkStateChangedCallbacks; +simgrid::surf::signal Link::onCreation; +simgrid::surf::signal Link::onDestruction; +simgrid::surf::signal Link::onStateChange; + simgrid::surf::signal networkActionStateChangedCallbacks; simgrid::surf::signal 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); } /********** diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index 2226805752..bd6def3522 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -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) 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) 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) 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) 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) 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 onCreation; + + /** @brief Callback signal fired when a Link is destroyed. + * Signature: void(Link*) */ + static simgrid::surf::signal 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 onStateChange; + /** @brief Get the bandwidth in bytes per second of current Link */ virtual double getBandwidth(); diff --git a/src/surf/plugins/energy.cpp b/src/surf/plugins/energy.cpp index be3fcd7a50..f320560dd7 100644 --- a/src/surf/plugins/energy.cpp +++ b/src/surf/plugins/energy.cpp @@ -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() -- 2.20.1