From 7cb738cbfc955558a7d598dae374b78fb44490f2 Mon Sep 17 00:00:00 2001 From: Christian Heinrich Date: Tue, 13 Feb 2018 17:41:52 +0100 Subject: [PATCH] [SURF] Move Action::suspended_ to new enum class SuspendedStates --- src/surf/cpu_cas01.cpp | 2 +- src/surf/cpu_ti.cpp | 16 ++++++++-------- src/surf/network_cm02.cpp | 2 +- src/surf/ptask_L07.cpp | 4 ++-- src/surf/storage_n11.cpp | 6 +++--- src/surf/surf_interface.cpp | 10 +++++----- src/surf/surf_interface.hpp | 8 +++++++- 7 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 1b9f80d3f9..369d1f78ab 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -175,7 +175,7 @@ CpuAction *CpuCas01::sleep(double duration) // FIXME: sleep variables should not consume 1.0 in System::expand() action->setMaxDuration(duration); - action->suspended_ = 2; + action->suspended_ = Action::SuspendStates::sleeping; if (duration < 0) { // NO_MAX_DURATION /* Move to the *end* of the corresponding action set. This convention is used to speed up update_resource_state */ simgrid::xbt::intrusive_erase(*action->getStateSet(), *action); diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 3fc88feb06..462b8065d7 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -473,7 +473,7 @@ void CpuTi::updateActionsFinishTime(double now) continue; /* action suspended, skip it */ - if (action.suspended_ != 0) + if (action.suspended_ != Action::SuspendStates::not_suspended) continue; sum_priority += 1.0 / action.getPriority(); @@ -487,7 +487,7 @@ void CpuTi::updateActionsFinishTime(double now) continue; /* verify if the action is really running on cpu */ - if (action.suspended_ == 0 && action.getPriority() > 0) { + if (action.suspended_ == Action::SuspendStates::not_suspended && action.getPriority() > 0) { /* total area needed to finish the action. Used in trace integration */ total_area = (action.getRemains()) * sum_priority * action.getPriority(); @@ -550,7 +550,7 @@ void CpuTi::updateRemainingAmount(double now) continue; /* action suspended, skip it */ - if (action.suspended_ != 0) + if (action.suspended_ != Action::SuspendStates::not_suspended) continue; /* action don't need update */ @@ -589,7 +589,7 @@ CpuAction *CpuTi::sleep(double duration) CpuTiAction* action = new CpuTiAction(static_cast(model()), 1.0, isOff(), this); action->setMaxDuration(duration); - action->suspended_ = 2; + action->suspended_ = Action::SuspendStates::sleeping; if (duration == NO_MAX_DURATION) { /* Move to the *end* of the corresponding action set. This convention is used to speed up update_resource_state */ simgrid::xbt::intrusive_erase(*action->getStateSet(), *action); @@ -660,8 +660,8 @@ void CpuTiAction::cancel() void CpuTiAction::suspend() { XBT_IN("(%p)", this); - if (suspended_ != 2) { - suspended_ = 1; + if (suspended_ != Action::SuspendStates::sleeping) { + suspended_ = Action::SuspendStates::suspended; heapRemove(getModel()->getActionHeap()); cpu_->modified(true); } @@ -671,8 +671,8 @@ void CpuTiAction::suspend() void CpuTiAction::resume() { XBT_IN("(%p)", this); - if (suspended_ != 2) { - suspended_ = 0; + if (suspended_ != Action::SuspendStates::sleeping) { + suspended_ = Action::SuspendStates::not_suspended; cpu_->modified(true); } XBT_OUT(); diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index e199003ab5..e13ab8fd84 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -464,7 +464,7 @@ void NetworkCm02Link::setLatency(double value) void NetworkCm02Action::updateRemainingLazy(double now) { - if (suspended_ != 0) + if (suspended_ != Action::SuspendStates::not_suspended) return; double delta = now - getLastUpdate(); diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index 33644e2506..8dcaf9b950 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -277,7 +277,7 @@ Action *CpuL07::sleep(double duration) { L07Action *action = static_cast(execution_start(1.0)); action->setMaxDuration(duration); - action->suspended_ = 2; + action->suspended_ = Action::SuspendStates::sleeping; model()->getMaxminSystem()->update_variable_weight(action->getVariable(), 0.0); return action; @@ -402,7 +402,7 @@ void L07Action::updateBound() } double lat_bound = sg_tcp_gamma / (2.0 * lat_current); XBT_DEBUG("action (%p) : lat_bound = %g", this, lat_bound); - if ((latency_ <= 0.0) && (suspended_ == 0)) { + if ((latency_ <= 0.0) && (suspended_ == Action::SuspendStates::not_suspended)) { if (rate_ < 0) getModel()->getMaxminSystem()->update_variable_bound(getVariable(), lat_bound); else diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index 130879dfa4..d7c60e3c67 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -162,9 +162,9 @@ void StorageN11Action::cancel() void StorageN11Action::suspend() { XBT_IN("(%p)", this); - if (suspended_ != 2) { + if (suspended_ != Action::SuspendStates::sleeping) { getModel()->getMaxminSystem()->update_variable_weight(getVariable(), 0.0); - suspended_ = 1; + suspended_ = Action::SuspendStates::suspended; } XBT_OUT(); } @@ -176,7 +176,7 @@ void StorageN11Action::resume() bool StorageN11Action::isSuspended() { - return suspended_ == 1; + return suspended_ == Action::SuspendStates::suspended; } void StorageN11Action::setMaxDuration(double /*duration*/) diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 7a5a55cd97..b69e67749a 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -717,7 +717,7 @@ int Action::unref(){ void Action::suspend() { XBT_IN("(%p)", this); - if (suspended_ != 2) { + if (suspended_ != SuspendStates::sleeping) { getModel()->getMaxminSystem()->update_variable_weight(getVariable(), 0.0); if (getModel()->getUpdateMechanism() == UM_LAZY){ heapRemove(getModel()->getActionHeap()); @@ -727,7 +727,7 @@ void Action::suspend() updateRemainingLazy(surf_get_clock()); } } - suspended_ = 1; + suspended_ = SuspendStates::suspended; } XBT_OUT(); } @@ -735,9 +735,9 @@ void Action::suspend() void Action::resume() { XBT_IN("(%p)", this); - if (suspended_ != 2) { + if (suspended_ != SuspendStates::sleeping) { getModel()->getMaxminSystem()->update_variable_weight(getVariable(), getPriority()); - suspended_ = 0; + suspended_ = SuspendStates::not_suspended; if (getModel()->getUpdateMechanism() == UM_LAZY) heapRemove(getModel()->getActionHeap()); } @@ -746,7 +746,7 @@ void Action::resume() bool Action::isSuspended() { - return suspended_ == 1; + return suspended_ == SuspendStates::suspended; } /* insert action on heap using a given key and a hat (heap_action_type) * a hat can be of three types for communications: diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 507c7ce916..8b16ee0294 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -129,6 +129,12 @@ public: not_in_the_system /**< Not in the system anymore. Why did you ask ? */ }; + enum class SuspendStates { + not_suspended = 0, /**< Action currently not suspended **/ + suspended, + sleeping + }; + /** * @brief Action constructor * @@ -280,7 +286,7 @@ public: enum heap_action_type getHat() const { return hat_; } bool is_linked() const { return action_lmm_hook.is_linked(); } protected: - int suspended_ = 0; + Action::SuspendStates suspended_ = Action::SuspendStates::not_suspended; }; typedef Action::ActionList ActionList; -- 2.20.1