From d67dd902c1ba20335b3446d7462d046f984ad3e4 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sun, 12 Nov 2017 16:13:00 +0100 Subject: [PATCH] Make Model::actionHeap_ private. --- src/surf/cpu_cas01.cpp | 3 --- src/surf/cpu_ti.cpp | 12 ++++-------- src/surf/network_cm02.cpp | 14 ++++++-------- src/surf/network_interface.cpp | 1 - src/surf/surf_interface.cpp | 4 +++- src/surf/surf_interface.hpp | 2 +- 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 40d145e9cd..aa47bfff92 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -55,8 +55,6 @@ CpuCas01Model::CpuCas01Model() : simgrid::surf::CpuModel() maxminSystem_ = lmm_system_new(selectiveUpdate_); if (getUpdateMechanism() == UM_LAZY) { - actionHeap_ = xbt_heap_new(8, nullptr); - xbt_heap_set_update_callback(actionHeap_, surf_action_lmm_update_index_heap); modifiedSet_ = new ActionLmmList(); maxminSystem_->keep_track = modifiedSet_; } @@ -66,7 +64,6 @@ CpuCas01Model::~CpuCas01Model() { lmm_system_free(maxminSystem_); maxminSystem_ = nullptr; - xbt_heap_free(actionHeap_); delete modifiedSet_; surf_cpu_model_pm = nullptr; diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index e36d98c70d..8818c2124e 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -331,9 +331,6 @@ CpuTiModel::CpuTiModel() : CpuModel() runningActionSetThatDoesNotNeedBeingChecked_ = new ActionList(); modifiedCpu_ = new CpuTiList(); - - actionHeap_ = xbt_heap_new(8, nullptr); - xbt_heap_set_update_callback(actionHeap_, surf_action_lmm_update_index_heap); } CpuTiModel::~CpuTiModel() @@ -341,7 +338,6 @@ CpuTiModel::~CpuTiModel() surf_cpu_model_pm = nullptr; delete runningActionSetThatDoesNotNeedBeingChecked_; delete modifiedCpu_; - xbt_heap_free(actionHeap_); } Cpu *CpuTiModel::createCpu(simgrid::s4u::Host *host, std::vector* speedPerPstate, int core) @@ -363,8 +359,8 @@ double CpuTiModel::nextOccuringEvent(double now) } /* get the min next event if heap not empty */ - if (xbt_heap_size(actionHeap_) > 0) - min_action_duration = xbt_heap_maxkey(actionHeap_) - now; + if (xbt_heap_size(getActionHeap()) > 0) + min_action_duration = xbt_heap_maxkey(getActionHeap()) - now; XBT_DEBUG("Share resources, min next event date: %f", min_action_duration); @@ -373,8 +369,8 @@ double CpuTiModel::nextOccuringEvent(double now) void CpuTiModel::updateActionsState(double now, double /*delta*/) { - while ((xbt_heap_size(actionHeap_) > 0) && (xbt_heap_maxkey(actionHeap_) <= now)) { - CpuTiAction* action = static_cast(xbt_heap_pop(actionHeap_)); + while ((xbt_heap_size(getActionHeap()) > 0) && (xbt_heap_maxkey(getActionHeap()) <= now)) { + CpuTiAction* action = static_cast(xbt_heap_pop(getActionHeap())); XBT_DEBUG("Action %p: finish", action); action->finish(Action::State::done); /* set the remains to 0 due to precision problems when updating the remaining amount */ diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 3761084782..35db28a6d4 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -153,8 +153,6 @@ NetworkCm02Model::NetworkCm02Model() loopback_ = createLink("__loopback__", 498000000, 0.000015, SURF_LINK_FATPIPE); if (getUpdateMechanism() == UM_LAZY) { - actionHeap_ = xbt_heap_new(8, nullptr); - xbt_heap_set_update_callback(actionHeap_, surf_action_lmm_update_index_heap); modifiedSet_ = new ActionLmmList(); maxminSystem_->keep_track = modifiedSet_; } @@ -173,10 +171,10 @@ LinkImpl* NetworkCm02Model::createLink(const std::string& name, double bandwidth void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/) { - while ((xbt_heap_size(actionHeap_) > 0) - && (double_equals(xbt_heap_maxkey(actionHeap_), now, sg_surf_precision))) { + while ((xbt_heap_size(getActionHeap()) > 0) && + (double_equals(xbt_heap_maxkey(getActionHeap()), now, sg_surf_precision))) { - NetworkCm02Action *action = static_cast (xbt_heap_pop(actionHeap_)); + NetworkCm02Action* action = static_cast(xbt_heap_pop(getActionHeap())); XBT_DEBUG("Something happened to action %p", action); if (TRACE_is_enabled()) { int n = lmm_get_number_of_cnst_from_var(maxminSystem_, action->getVariable()); @@ -195,7 +193,7 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/) if (action->getHat() == LATENCY) { XBT_DEBUG("Latency paid for action %p. Activating", action); lmm_update_variable_weight(maxminSystem_, action->getVariable(), action->weight_); - action->heapRemove(actionHeap_); + action->heapRemove(getActionHeap()); action->refreshLastUpdate(); // if I am wearing a max_duration or normal hat @@ -205,7 +203,7 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/) XBT_DEBUG("Action %p finished", action); action->setRemains(0); action->finish(Action::State::done); - action->heapRemove(actionHeap_); + action->heapRemove(getActionHeap()); } } } @@ -318,7 +316,7 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz if (getUpdateMechanism() == UM_LAZY) { // add to the heap the event when the latency is payed XBT_DEBUG("Added action (%p) one latency event at date %f", action, action->latency_ + action->getLastUpdate()); - action->heapInsert(actionHeap_, action->latency_ + action->getLastUpdate(), route.empty() ? NORMAL : LATENCY); + action->heapInsert(getActionHeap(), action->latency_ + action->getLastUpdate(), route.empty() ? NORMAL : LATENCY); } } else action->setVariable(lmm_variable_new(maxminSystem_, action, 1.0, -1.0, constraints_per_variable)); diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index a7803a93fe..2bbbd86994 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -63,7 +63,6 @@ namespace simgrid { NetworkModel::~NetworkModel() { lmm_system_free(maxminSystem_); - xbt_heap_free(actionHeap_); delete modifiedSet_; } diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index f9c967919a..13ee74b230 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -365,12 +365,14 @@ Model::Model() doneActionSet_ = new ActionList(); modifiedSet_ = nullptr; - actionHeap_ = nullptr; + actionHeap_ = xbt_heap_new(8, nullptr); + xbt_heap_set_update_callback(actionHeap_, surf_action_lmm_update_index_heap); updateMechanism_ = UM_UNDEFINED; selectiveUpdate_ = 0; } Model::~Model(){ + xbt_heap_free(actionHeap_); delete readyActionSet_; delete runningActionSet_; delete failedActionSet_; diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index f569ce7ffc..1ace36da3f 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -333,7 +333,6 @@ protected: ActionLmmListPtr modifiedSet_; lmm_system_t maxminSystem_ = nullptr; bool selectiveUpdate_; - xbt_heap_t actionHeap_; private: e_UM_t updateMechanism_ = UM_UNDEFINED; @@ -341,6 +340,7 @@ private: ActionList* runningActionSet_; /**< Actions in state SURF_ACTION_RUNNING */ ActionList* failedActionSet_; /**< Actions in state SURF_ACTION_FAILED */ ActionList* doneActionSet_; /**< Actions in state SURF_ACTION_DONE */ + xbt_heap_t actionHeap_; }; } -- 2.20.1