From: Arnaud Giersch Date: Sun, 12 Nov 2017 17:56:45 +0000 (+0100) Subject: Define helper methods to access actionHeap_. X-Git-Tag: v3.18~242^2~52 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/e7fe297bcf61069ab362adcdc1a177365a0896c7 Define helper methods to access actionHeap_. --- diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index 044d58fca3..554c8715ef 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -23,10 +23,9 @@ namespace surf { void CpuModel::updateActionsStateLazy(double now, double /*delta*/) { - while ((xbt_heap_size(getActionHeap()) > 0) - && (double_equals(xbt_heap_maxkey(getActionHeap()), now, sg_surf_precision))) { + while (not actionHeapIsEmpty() && double_equals(actionHeapTopDate(), now, sg_surf_precision)) { - CpuAction *action = static_cast(xbt_heap_pop(getActionHeap())); + CpuAction* action = static_cast(actionHeapPop()); XBT_CDEBUG(surf_kernel, "Something happened to action %p", action); if (TRACE_is_enabled()) { Cpu *cpu = static_cast(lmm_constraint_id(lmm_get_cnst_from_var(getMaxminSystem(), action->getVariable(), 0))); diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 8818c2124e..42d080fe99 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -359,8 +359,8 @@ double CpuTiModel::nextOccuringEvent(double now) } /* get the min next event if heap not empty */ - if (xbt_heap_size(getActionHeap()) > 0) - min_action_duration = xbt_heap_maxkey(getActionHeap()) - now; + if (not actionHeapIsEmpty()) + min_action_duration = actionHeapTopDate() - now; XBT_DEBUG("Share resources, min next event date: %f", min_action_duration); @@ -369,8 +369,8 @@ double CpuTiModel::nextOccuringEvent(double now) void CpuTiModel::updateActionsState(double now, double /*delta*/) { - while ((xbt_heap_size(getActionHeap()) > 0) && (xbt_heap_maxkey(getActionHeap()) <= now)) { - CpuTiAction* action = static_cast(xbt_heap_pop(getActionHeap())); + while (not actionHeapIsEmpty() && actionHeapTopDate() <= now) { + CpuTiAction* action = static_cast(actionHeapPop()); 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 35db28a6d4..e1896d35af 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -171,10 +171,9 @@ LinkImpl* NetworkCm02Model::createLink(const std::string& name, double bandwidth void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/) { - while ((xbt_heap_size(getActionHeap()) > 0) && - (double_equals(xbt_heap_maxkey(getActionHeap()), now, sg_surf_precision))) { + while (not actionHeapIsEmpty() && double_equals(actionHeapTopDate(), now, sg_surf_precision)) { - NetworkCm02Action* action = static_cast(xbt_heap_pop(getActionHeap())); + NetworkCm02Action* action = static_cast(actionHeapPop()); XBT_DEBUG("Something happened to action %p", action); if (TRACE_is_enabled()) { int n = lmm_get_number_of_cnst_from_var(maxminSystem_, action->getVariable()); diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 13ee74b230..01318caa06 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -444,8 +444,8 @@ double Model::nextOccuringEventLazy(double now) } //hereafter must have already the min value for this resource model - if (xbt_heap_size(actionHeap_) > 0) { - double min = xbt_heap_maxkey(actionHeap_) - now; + if (not actionHeapIsEmpty()) { + double min = actionHeapTopDate() - now; XBT_DEBUG("minimum with the HEAP %f", min); return min; } else { diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 1ace36da3f..719a3c4b86 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -302,6 +302,10 @@ public: /** @brief Get Action heap */ xbt_heap_t getActionHeap() {return actionHeap_;} + double actionHeapTopDate() const { return xbt_heap_maxkey(actionHeap_); } + Action* actionHeapPop() { return static_cast(xbt_heap_pop(actionHeap_)); } + bool actionHeapIsEmpty() const { return xbt_heap_size(actionHeap_) == 0; } + /** * @brief Share the resources between the actions *