From 6050383ef0dc59e1ca54d02bcf6bccb993593add Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 20 Mar 2016 23:21:36 +0100 Subject: [PATCH] objectifies surf::Action::State --- src/include/surf/surf.h | 19 +---------- src/simix/smx_host.cpp | 2 +- src/simix/smx_io.cpp | 4 +-- src/simix/smx_network.cpp | 12 +++---- src/simix/smx_process.cpp | 4 +-- src/simix/smx_synchro.cpp | 4 +-- src/surf/cpu_cas01.cpp | 8 ++--- src/surf/cpu_interface.cpp | 14 ++++---- src/surf/cpu_interface.hpp | 7 ++-- src/surf/cpu_ti.cpp | 14 ++++---- src/surf/cpu_ti.hpp | 2 +- src/surf/network_cm02.cpp | 16 ++++----- src/surf/network_constant.cpp | 4 +-- src/surf/network_ib.cpp | 4 +-- src/surf/network_interface.cpp | 6 ++-- src/surf/network_interface.hpp | 6 ++-- src/surf/network_ns3.cpp | 4 +-- src/surf/plugins/energy.cpp | 2 +- src/surf/ptask_L07.cpp | 6 ++-- src/surf/storage_interface.cpp | 12 +++---- src/surf/storage_interface.hpp | 6 ++-- src/surf/storage_n11.cpp | 10 +++--- src/surf/surf_interface.cpp | 41 +++++++++++++----------- src/surf/surf_interface.hpp | 14 ++++++-- src/surf/vm_hl13.cpp | 6 ++-- teshsuite/surf/surf_usage/surf_usage.cpp | 18 +++++------ 26 files changed, 120 insertions(+), 125 deletions(-) diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 9b0bd39211..fa33de3981 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -140,24 +140,7 @@ typedef struct surf_model_description { XBT_PUBLIC(int) find_model_description(s_surf_model_description_t * table, const char *name); XBT_PUBLIC(void) model_help(const char *category, s_surf_model_description_t * table); -/** @ingroup SURF_interface - * @brief Action states - * - * @see Action - */ -typedef enum { - SURF_ACTION_READY = 0, /**< Ready */ - SURF_ACTION_RUNNING, /**< Running */ - SURF_ACTION_FAILED, /**< Task Failure */ - SURF_ACTION_DONE, /**< Completed */ - SURF_ACTION_TO_FREE, /**< Action to free in next cleanup */ - SURF_ACTION_NOT_IN_THE_SYSTEM /**< Not in the system anymore. Why did you ask ? */ -} e_surf_action_state_t; - -/** @ingroup SURF_vm_interface - * - * - */ +/** @ingroup SURF_vm_interface */ /* FIXME: Where should the VM state be defined? */ typedef enum { SURF_VM_STATE_CREATED, /**< created, but not yet started */ diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index 3ec8f1707a..4c0fd124f1 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -483,7 +483,7 @@ void SIMIX_post_host_execute(smx_synchro_t synchro) /* If the host running the synchro failed, notice it so that the asking * process can be killed if it runs on that host itself */ synchro->state = SIMIX_FAILED; - } else if (synchro->execution.surf_exec->getState() == SURF_ACTION_FAILED) { + } else if (synchro->execution.surf_exec->getState() == simgrid::surf::Action::State::failed) { /* If the host running the synchro didn't fail, then the synchro was * canceled */ synchro->state = SIMIX_CANCELED; diff --git a/src/simix/smx_io.cpp b/src/simix/smx_io.cpp index 046ff2f14b..96224c608e 100644 --- a/src/simix/smx_io.cpp +++ b/src/simix/smx_io.cpp @@ -326,11 +326,11 @@ void SIMIX_post_io(smx_synchro_t synchro) switch (synchro->io.surf_io->getState()) { - case SURF_ACTION_FAILED: + case simgrid::surf::Action::State::failed: synchro->state = SIMIX_FAILED; break; - case SURF_ACTION_DONE: + case simgrid::surf::Action::State::done: synchro->state = SIMIX_DONE; break; diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index b57a60edc2..9b79a4f915 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -707,7 +707,7 @@ static inline void SIMIX_comm_start(smx_synchro_t synchro) synchro->state = SIMIX_RUNNING; /* If a link is failed, detect it immediately */ - if (synchro->comm.surf_comm->getState() == SURF_ACTION_FAILED) { + if (synchro->comm.surf_comm->getState() == simgrid::surf::Action::State::failed) { XBT_DEBUG("Communication from '%s' to '%s' failed to start because of a link failure", sg_host_get_name(sender), sg_host_get_name(receiver)); synchro->state = SIMIX_LINK_FAILURE; @@ -875,19 +875,19 @@ void SIMIX_post_comm(smx_synchro_t synchro) { /* Update synchro state */ if (synchro->comm.src_timeout && - synchro->comm.src_timeout->getState() == SURF_ACTION_DONE) + synchro->comm.src_timeout->getState() == simgrid::surf::Action::State::done) synchro->state = SIMIX_SRC_TIMEOUT; else if (synchro->comm.dst_timeout && - synchro->comm.dst_timeout->getState() == SURF_ACTION_DONE) + synchro->comm.dst_timeout->getState() == simgrid::surf::Action::State::done) synchro->state = SIMIX_DST_TIMEOUT; else if (synchro->comm.src_timeout && - synchro->comm.src_timeout->getState() == SURF_ACTION_FAILED) + synchro->comm.src_timeout->getState() == simgrid::surf::Action::State::failed) synchro->state = SIMIX_SRC_HOST_FAILURE; else if (synchro->comm.dst_timeout && - synchro->comm.dst_timeout->getState() == SURF_ACTION_FAILED) + synchro->comm.dst_timeout->getState() == simgrid::surf::Action::State::failed) synchro->state = SIMIX_DST_HOST_FAILURE; else if (synchro->comm.surf_comm && - synchro->comm.surf_comm->getState() == SURF_ACTION_FAILED) { + synchro->comm.surf_comm->getState() == simgrid::surf::Action::State::failed) { XBT_DEBUG("Puta madre. Surf says that the link broke"); synchro->state = SIMIX_LINK_FAILURE; } else diff --git a/src/simix/smx_process.cpp b/src/simix/smx_process.cpp index 81e6ab50b5..93c852ed1f 100644 --- a/src/simix/smx_process.cpp +++ b/src/simix/smx_process.cpp @@ -926,13 +926,13 @@ void SIMIX_post_process_sleep(smx_synchro_t synchro) while ((simcall = (smx_simcall_t) xbt_fifo_shift(synchro->simcalls))) { switch (synchro->sleep.surf_sleep->getState()){ - case SURF_ACTION_FAILED: + case simgrid::surf::Action::State::failed: simcall->issuer->context->iwannadie = 1; //SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed"); state = SIMIX_SRC_HOST_FAILURE; break; - case SURF_ACTION_DONE: + case simgrid::surf::Action::State::done: state = SIMIX_DONE; break; diff --git a/src/simix/smx_synchro.cpp b/src/simix/smx_synchro.cpp index b8eff39b8b..de245a8ec7 100644 --- a/src/simix/smx_synchro.cpp +++ b/src/simix/smx_synchro.cpp @@ -82,9 +82,9 @@ void SIMIX_post_synchro(smx_synchro_t synchro) { XBT_IN("(%p)",synchro); xbt_assert(synchro->type == SIMIX_SYNC_SYNCHRO); - if (synchro->synchro.sleep->getState() == SURF_ACTION_FAILED) + if (synchro->synchro.sleep->getState() == simgrid::surf::Action::State::failed) synchro->state = SIMIX_FAILED; - else if(synchro->synchro.sleep->getState() == SURF_ACTION_DONE) + else if(synchro->synchro.sleep->getState() == simgrid::surf::Action::State::done) synchro->state = SIMIX_SRC_TIMEOUT; SIMIX_synchro_finish(synchro); diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 2c4435c3da..d48972e75f 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -164,11 +164,11 @@ void CpuCas01::apply_event(tmgr_trace_iterator_t event, double value) while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), cnst, &elem))) { Action *action = static_cast(lmm_variable_id(var)); - if (action->getState() == SURF_ACTION_RUNNING || - action->getState() == SURF_ACTION_READY || - action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) { + if (action->getState() == Action::State::running || + action->getState() == Action::State::ready || + action->getState() == Action::State::not_in_the_system) { action->setFinishTime(date); - action->setState(SURF_ACTION_FAILED); + action->setState(Action::State::failed); } } } diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index 94ba64d1d0..cb9e788417 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -24,7 +24,7 @@ namespace surf { * Callbacks * *************/ -simgrid::xbt::signal cpuActionStateChangedCallbacks; +simgrid::xbt::signal cpuActionStateChangedCallbacks; /********* * Model * @@ -50,7 +50,7 @@ void CpuModel::updateActionsStateLazy(double now, double /*delta*/) /* set the remains to 0 due to precision problems when updating the remaining amount */ action->setRemains(0); - action->setState(SURF_ACTION_DONE); + action->setState(Action::State::done); action->heapRemove(getActionHeap()); //FIXME: strange call since action was already popped } if (TRACE_is_enabled()) { @@ -106,11 +106,11 @@ void CpuModel::updateActionsStateFull(double now, double delta) if ((action->getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) { action->finish(); - action->setState(SURF_ACTION_DONE); + action->setState(Action::State::done); } else if ((action->getMaxDuration() != NO_MAX_DURATION) && (action->getMaxDuration() <= 0)) { action->finish(); - action->setState(SURF_ACTION_DONE); + action->setState(Action::State::done); } } } @@ -330,10 +330,10 @@ void CpuAction::setAffinity(Cpu *cpu, unsigned long mask) XBT_OUT(); } -simgrid::xbt::signal CpuAction::onStateChange; +simgrid::xbt::signal CpuAction::onStateChange; -void CpuAction::setState(e_surf_action_state_t state){ - e_surf_action_state_t previous = getState(); +void CpuAction::setState(Action::State state){ + Action::State previous = getState(); Action::setState(state); onStateChange(this, previous); } diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 380e6b733c..57165412ee 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -148,9 +148,9 @@ XBT_PUBLIC_CLASS CpuAction : public simgrid::surf::Action { friend XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action); public: /** @brief Callbacks handler which emit the callbacks after CpuAction State changed * - * @details Callback functions have the following signature: `void(CpuAction *action, e_surf_action_state_t previous)` + * @details Callback functions have the following signature: `void(CpuAction *action, simgrid::surf::Action::State previous)` */ - static simgrid::xbt::signal onStateChange; + static simgrid::xbt::signal onStateChange; CpuAction(simgrid::surf::Model *model, double cost, bool failed) : Action(model, cost, failed) {} //FIXME:DEADCODE? @@ -160,11 +160,10 @@ public: /** @brief Set the affinity of the current CpuAction */ virtual void setAffinity(Cpu *cpu, unsigned long mask); - void setState(e_surf_action_state_t state); + void setState(simgrid::surf::Action::State state) override; void updateRemainingLazy(double now); std::list cpus(); - }; } diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 39c4b5c916..4e7b6e61d5 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -449,7 +449,7 @@ void CpuTiModel::updateActionsState(double now, double /*delta*/) action->finish(); /* set the remains to 0 due to precision problems when updating the remaining amount */ action->setRemains(0); - action->setState(SURF_ACTION_DONE); + action->setState(Action::State::done); /* update remaining amount of all actions */ action->cpu_->updateRemainingAmount(surf_get_clock()); } @@ -533,11 +533,11 @@ void CpuTi::apply_event(tmgr_trace_iterator_t event, double value) ; it != itend ; ++it) { CpuTiAction *action = &*it; - if (action->getState() == SURF_ACTION_RUNNING - || action->getState() == SURF_ACTION_READY - || action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) { + if (action->getState() == Action::State::running + || action->getState() == Action::State::ready + || action->getState() == Action::State::not_in_the_system) { action->setFinishTime(date); - action->setState(SURF_ACTION_FAILED); + action->setState(Action::State::failed); if (action->indexHeap_ >= 0) { CpuTiAction *heap_act = (CpuTiAction*) xbt_heap_remove(static_cast(getModel())->tiActionHeap_, action->indexHeap_); @@ -748,7 +748,7 @@ void CpuTiAction::updateIndexHeap(int i) indexHeap_ = i; } -void CpuTiAction::setState(e_surf_action_state_t state) +void CpuTiAction::setState(Action::State state) { CpuAction::setState(state); cpu_->modified(true); @@ -774,7 +774,7 @@ int CpuTiAction::unref() void CpuTiAction::cancel() { - this->setState(SURF_ACTION_FAILED); + this->setState(Action::State::failed); xbt_heap_remove(getModel()->getActionHeap(), this->indexHeap_); cpu_->modified(true); return; diff --git a/src/surf/cpu_ti.hpp b/src/surf/cpu_ti.hpp index bf841ed359..9d3491d8c6 100644 --- a/src/surf/cpu_ti.hpp +++ b/src/surf/cpu_ti.hpp @@ -84,7 +84,7 @@ class CpuTiAction: public CpuAction { public: CpuTiAction(CpuTiModel *model, double cost, bool failed, CpuTi *cpu); - void setState(e_surf_action_state_t state) override; + void setState(simgrid::surf::Action::State state) override; int unref() override; void cancel() override; void updateIndexHeap(int i); diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index d88a052134..a32ccb8033 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -215,7 +215,7 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/) XBT_DEBUG("Action %p finished", action); action->setRemains(0); action->finish(); - action->setState(SURF_ACTION_DONE); + action->setState(Action::State::done); action->heapRemove(actionHeap_); action->gapRemove(); @@ -280,12 +280,12 @@ void NetworkCm02Model::updateActionsStateFull(double now, double delta) if ((action->getRemains() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) { action->finish(); - action->setState(SURF_ACTION_DONE); + action->setState(Action::State::done); action->gapRemove(); } else if (((action->getMaxDuration() != NO_MAX_DURATION) && (action->getMaxDuration() <= 0))) { action->finish(); - action->setState(SURF_ACTION_DONE); + action->setState(Action::State::done); action->gapRemove(); } } @@ -438,10 +438,10 @@ void NetworkCm02Link::apply_event(tmgr_trace_iterator_t triggered, double value) while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), getConstraint(), &elem))) { Action *action = static_cast( lmm_variable_id(var) ); - if (action->getState() == SURF_ACTION_RUNNING || - action->getState() == SURF_ACTION_READY) { + if (action->getState() == Action::State::running || + action->getState() == Action::State::ready) { action->setFinishTime(now); - action->setState(SURF_ACTION_FAILED); + action->setState(Action::State::failed); } } } @@ -532,13 +532,13 @@ void NetworkCm02Action::updateRemainingLazy(double now) if (m_remains <= 0 && (lmm_get_variable_weight(getVariable()) > 0)) { finish(); - setState(SURF_ACTION_DONE); + setState(Action::State::done); heapRemove(getModel()->getActionHeap()); } else if (((m_maxDuration != NO_MAX_DURATION) && (m_maxDuration <= 0))) { finish(); - setState(SURF_ACTION_DONE); + setState(Action::State::done); heapRemove(getModel()->getActionHeap()); } diff --git a/src/surf/network_constant.cpp b/src/surf/network_constant.cpp index d7dd2ad8e1..e68c91d532 100644 --- a/src/surf/network_constant.cpp +++ b/src/surf/network_constant.cpp @@ -69,11 +69,11 @@ namespace simgrid { if (action->getRemainsNoUpdate() <= 0) { action->finish(); - action->setState(SURF_ACTION_DONE); + action->setState(Action::State::done); } else if ((action->getMaxDuration() != NO_MAX_DURATION) && (action->getMaxDuration() <= 0)) { action->finish(); - action->setState(SURF_ACTION_DONE); + action->setState(Action::State::done); } } } diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index d373a381fc..de2c180fa3 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -33,10 +33,10 @@ static void IB_create_host_callback(simgrid::s4u::Host& host){ static void IB_action_state_changed_callback( simgrid::surf::NetworkAction *action, - e_surf_action_state_t statein, e_surf_action_state_t stateout) + simgrid::surf::Action::State statein, simgrid::surf::Action::State stateout) { using namespace simgrid::surf; - if(statein!=SURF_ACTION_RUNNING|| stateout!=SURF_ACTION_DONE) + if(statein!=simgrid::surf::Action::State::running || stateout!=simgrid::surf::Action::State::done) return; std::pair pair = ((NetworkIBModel*)surf_network_model)->active_comms[action]; XBT_DEBUG("IB callback - action %p finished", action); diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index ae90c04033..a4b3e23078 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -95,7 +95,7 @@ namespace simgrid { simgrid::xbt::signal Link::onDestruction; simgrid::xbt::signal Link::onStateChange; - simgrid::xbt::signal networkActionStateChangedCallbacks; + simgrid::xbt::signal networkActionStateChangedCallbacks; simgrid::xbt::signal networkCommunicateCallbacks; } @@ -265,8 +265,8 @@ namespace simgrid { * Action * **********/ - void NetworkAction::setState(e_surf_action_state_t state){ - e_surf_action_state_t old = getState(); + void NetworkAction::setState(Action::State state){ + Action::State old = getState(); Action::setState(state); networkActionStateChangedCallbacks(this, old, state); } diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index 0369963ced..4b4c2567b7 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -35,8 +35,8 @@ namespace simgrid { /** @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::xbt::signal) networkActionStateChangedCallbacks; + * Signature: `void(NetworkAction *action, simgrid::surf::Action::State old, simgrid::surf::Action::State current)` */ + XBT_PUBLIC_DATA(simgrid::xbt::signal) networkActionStateChangedCallbacks; /** @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)` */ @@ -274,7 +274,7 @@ namespace simgrid { NetworkAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var) : simgrid::surf::Action(model, cost, failed, var) {}; - void setState(e_surf_action_state_t state); + void setState(simgrid::surf::Action::State state) override; double latency_; double latCurrent_; diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 59a28ea24b..d3f0405fda 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -323,7 +323,7 @@ void NetworkNS3Model::updateActionsState(double now, double delta) action->setRemains(action->getCost() - ns3_get_socket_sent(data)); if (TRACE_is_enabled() && - action->getState() == SURF_ACTION_RUNNING){ + action->getState() == Action::State::running){ double data_sent = ns3_get_socket_sent(data); double data_delta_sent = data_sent - action->m_lastSent; @@ -341,7 +341,7 @@ void NetworkNS3Model::updateActionsState(double now, double delta) xbt_dynar_push(socket_to_destroy,&key); XBT_DEBUG("Destroy socket %p of action %p", key, action); action->finish(); - action->setState(SURF_ACTION_DONE); + action->setState(Action::State::done); } } diff --git a/src/surf/plugins/energy.cpp b/src/surf/plugins/energy.cpp index fdd672dee1..8abd780c03 100644 --- a/src/surf/plugins/energy.cpp +++ b/src/surf/plugins/energy.cpp @@ -205,7 +205,7 @@ static void onCreation(simgrid::s4u::Host& host) { host.extension_set(new HostEnergy(&host)); } -static void onActionStateChange(simgrid::surf::CpuAction *action, e_surf_action_state_t previous) { +static void onActionStateChange(simgrid::surf::CpuAction *action, simgrid::surf::Action::State previous) { for(simgrid::surf::Cpu* cpu : action->cpus()) { const char *name = cpu->getName(); sg_host_t sghost = sg_host_by_name(name); diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index be2a6009d6..558a96b2e7 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -143,11 +143,11 @@ void HostL07Model::updateActionsState(double /*now*/, double delta) { if ((action->getRemains() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) { action->finish(); - action->setState(SURF_ACTION_DONE); + action->setState(Action::State::done); } else if ((action->getMaxDuration() != NO_MAX_DURATION) && (action->getMaxDuration() <= 0)) { action->finish(); - action->setState(SURF_ACTION_DONE); + action->setState(Action::State::done); } else { /* Need to check that none of the model has failed */ lmm_constraint_t cnst = NULL; @@ -159,7 +159,7 @@ void HostL07Model::updateActionsState(double /*now*/, double delta) { if (static_cast(constraint_id)->isOff()) { XBT_DEBUG("Action (%p) Failed!!", action); action->finish(); - action->setState(SURF_ACTION_FAILED); + action->setState(Action::State::failed); break; } } diff --git a/src/surf/storage_interface.cpp b/src/surf/storage_interface.cpp index 61c105c8af..cf639a3db7 100644 --- a/src/surf/storage_interface.cpp +++ b/src/surf/storage_interface.cpp @@ -27,10 +27,10 @@ namespace surf { * Callbacks * *************/ -simgrid::xbt::signal storageCreatedCallbacks; -simgrid::xbt::signal storageDestructedCallbacks; -simgrid::xbt::signal storageStateChangedCallbacks; // signature: wasOn, isOn -simgrid::xbt::signal storageActionStateChangedCallbacks; +simgrid::xbt::signal storageCreatedCallbacks; +simgrid::xbt::signal storageDestructedCallbacks; +simgrid::xbt::signal storageStateChangedCallbacks; // signature: wasOn, isOn +simgrid::xbt::signal storageActionStateChangedCallbacks; /********* * Model * @@ -196,8 +196,8 @@ StorageAction::StorageAction(Model *model, double cost, bool failed, lmm_variabl progress = 0; } -void StorageAction::setState(e_surf_action_state_t state){ - e_surf_action_state_t old = getState(); +void StorageAction::setState(Action::State state){ + Action::State old = getState(); Action::setState(state); storageActionStateChangedCallbacks(this, old, state); } diff --git a/src/surf/storage_interface.hpp b/src/surf/storage_interface.hpp index 3ba65bf50b..e00bd45a8b 100644 --- a/src/surf/storage_interface.hpp +++ b/src/surf/storage_interface.hpp @@ -48,9 +48,9 @@ XBT_PUBLIC_DATA(simgrid::xbt::signal) s /** @ingroup SURF_callbacks * @brief Callbacks handler which emit the callbacks after StorageAction State changed * - * @details Callback functions have the following signature: `void(StorageAction *action, e_surf_action_state_t old, e_surf_action_state_t current)` + * @details Callback functions have the following signature: `void(StorageAction *action, simgrid::surf::Action::State old, simgrid::surf::Action::State current)` */ -XBT_PUBLIC_DATA(simgrid::xbt::signal) storageActionStateChangedCallbacks; +XBT_PUBLIC_DATA(simgrid::xbt::signal) storageActionStateChangedCallbacks; /********* * Model * @@ -268,7 +268,7 @@ public: StorageAction(Model *model, double cost, bool failed, lmm_variable_t var, Storage *storage, e_surf_action_storage_type_t type); - void setState(e_surf_action_state_t state); + void setState(simgrid::surf::Action::State state) override; e_surf_action_storage_type_t m_type; Storage *p_storage; diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index e64788558e..81308c10d7 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -201,17 +201,17 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta) action->p_storage->m_usedSize == action->p_storage->m_size) { action->finish(); - action->setState(SURF_ACTION_FAILED); + action->setState(Action::State::failed); } else if ((action->getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) { action->finish(); - action->setState(SURF_ACTION_DONE); + action->setState(Action::State::done); } else if ((action->getMaxDuration() != NO_MAX_DURATION) && (action->getMaxDuration() <= 0)) { action->finish(); - action->setState(SURF_ACTION_DONE); + action->setState(Action::State::done); } } return; @@ -309,7 +309,7 @@ StorageAction *StorageN11::write(surf_file_t fd, sg_size_t size) m_usedSize -= (fd->size - fd->current_position); // If the storage is full before even starting to write if(m_usedSize==m_size) { - action->setState(SURF_ACTION_FAILED); + action->setState(Action::State::failed); } return action; } @@ -365,7 +365,7 @@ int StorageN11Action::unref() void StorageN11Action::cancel() { - setState(SURF_ACTION_FAILED); + setState(Action::State::failed); return; } diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 1dcc7540a1..6373037916 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -674,38 +674,41 @@ void Action::finish() { m_finish = surf_get_clock(); } -e_surf_action_state_t Action::getState() +Action::State Action::getState() { if (p_stateSet == getModel()->getReadyActionSet()) - return SURF_ACTION_READY; + return Action::State::ready; if (p_stateSet == getModel()->getRunningActionSet()) - return SURF_ACTION_RUNNING; + return Action::State::running; if (p_stateSet == getModel()->getFailedActionSet()) - return SURF_ACTION_FAILED; + return Action::State::failed; if (p_stateSet == getModel()->getDoneActionSet()) - return SURF_ACTION_DONE; - return SURF_ACTION_NOT_IN_THE_SYSTEM; + return Action::State::done; + return Action::State::not_in_the_system; } -void Action::setState(e_surf_action_state_t state) +void Action::setState(Action::State state) { - //surf_action_state_t action_state = &(action->model_type->states); - XBT_IN("(%p,%s)", this, surf_action_state_names[state]); p_stateSet->erase(p_stateSet->iterator_to(*this)); - if (state == SURF_ACTION_READY) + switch (state) { + case Action::State::ready: p_stateSet = getModel()->getReadyActionSet(); - else if (state == SURF_ACTION_RUNNING) + break; + case Action::State::running: p_stateSet = getModel()->getRunningActionSet(); - else if (state == SURF_ACTION_FAILED) + break; + case Action::State::failed: p_stateSet = getModel()->getFailedActionSet(); - else if (state == SURF_ACTION_DONE) + break; + case Action::State::done: p_stateSet = getModel()->getDoneActionSet(); - else + break; + default: p_stateSet = NULL; - + break; + } if (p_stateSet) p_stateSet->push_back(*this); - XBT_OUT(); } double Action::getBound() @@ -774,7 +777,7 @@ void Action::setPriority(double priority) } void Action::cancel(){ - setState(SURF_ACTION_FAILED); + setState(Action::State::failed); if (getModel()->getUpdateMechanism() == UM_LAZY) { if (action_lmm_hook.is_linked()) getModel()->getModifiedSet()->erase(getModel()->getModifiedSet()->iterator_to(*this)); @@ -922,12 +925,12 @@ void Action::updateRemainingLazy(double now) if ((m_remains <= 0) && (lmm_get_variable_weight(getVariable()) > 0)) { finish(); - setState(SURF_ACTION_DONE); + setState(Action::State::done); heapRemove(getModel()->getActionHeap()); } else if (((m_maxDuration != NO_MAX_DURATION) && (m_maxDuration <= 0))) { finish(); - setState(SURF_ACTION_DONE); + setState(Action::State::done); heapRemove(getModel()->getActionHeap()); } } diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 6d98129bf2..f51e48b690 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -97,6 +97,16 @@ public: typedef boost::intrusive::member_hook< Action, boost::intrusive::list_member_hook<>, &Action::action_hook> ActionOptions; typedef boost::intrusive::list ActionList; + + enum class State { + ready = 0, /**< Ready */ + running, /**< Running */ + failed, /**< Task Failure */ + done, /**< Completed */ + to_free, /**< Action to free in next cleanup */ + not_in_the_system /**< Not in the system anymore. Why did you ask ? */ + }; + private: /** * @brief Common initializations for the constructors @@ -131,9 +141,9 @@ public: void finish(); /** @brief Get the [state](\ref e_surf_action_state_t) of the current Action */ - e_surf_action_state_t getState(); /**< get the state*/ + Action::State getState(); /**< get the state*/ /** @brief Set the [state](\ref e_surf_action_state_t) of the current Action */ - virtual void setState(e_surf_action_state_t state); + virtual void setState(Action::State state); /** @brief Get the bound of the current Action */ double getBound(); diff --git a/src/surf/vm_hl13.cpp b/src/surf/vm_hl13.cpp index 63248cf617..b17a570aa6 100644 --- a/src/surf/vm_hl13.cpp +++ b/src/surf/vm_hl13.cpp @@ -193,9 +193,9 @@ void VMHL13::migrate(sg_host_t host_dest) /* create a cpu action bound to the pm model at the destination. */ CpuAction *new_cpu_action = static_cast(host_dest->pimpl_cpu->execution_start(0)); - e_surf_action_state_t state = p_action->getState(); - if (state != SURF_ACTION_DONE) - XBT_CRITICAL("FIXME: may need a proper handling, %d", state); + Action::State state = p_action->getState(); + if (state != Action::State::done) + XBT_CRITICAL("FIXME: may need a proper handling, %d", static_cast(state)); if (p_action->getRemainsNoUpdate() > 0) XBT_CRITICAL("FIXME: need copy the state(?), %f", p_action->getRemainsNoUpdate()); diff --git a/teshsuite/surf/surf_usage/surf_usage.cpp b/teshsuite/surf/surf_usage/surf_usage.cpp index 4b5a9e903f..17c8002669 100644 --- a/teshsuite/surf/surf_usage/surf_usage.cpp +++ b/teshsuite/surf/surf_usage/surf_usage.cpp @@ -16,18 +16,18 @@ #include "xbt/log.h" XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example"); -static const char *string_action(e_surf_action_state_t state) +static const char *string_action(simgrid::surf::Action::State state) { switch (state) { - case (SURF_ACTION_READY): + case (simgrid::surf::Action::State::ready): return "SURF_ACTION_READY"; - case (SURF_ACTION_RUNNING): + case (simgrid::surf::Action::State::running): return "SURF_ACTION_RUNNING"; - case (SURF_ACTION_FAILED): + case (simgrid::surf::Action::State::failed): return "SURF_ACTION_FAILED"; - case (SURF_ACTION_DONE): + case (simgrid::surf::Action::State::done): return "SURF_ACTION_DONE"; - case (SURF_ACTION_NOT_IN_THE_SYSTEM): + case (simgrid::surf::Action::State::not_in_the_system): return "SURF_ACTION_NOT_IN_THE_SYSTEM"; default: return "INVALID STATE"; @@ -59,9 +59,9 @@ int main(int argc, char **argv) surf_action_t actionC = surf_host_sleep(hostB, 7.32); /* Use whatever calling style you want... */ - e_surf_action_state_t stateActionA = actionA->getState(); /* When you know actionA model type */ - e_surf_action_state_t stateActionB = actionB->getState(); /* If you're unsure about it's model type */ - e_surf_action_state_t stateActionC = actionC->getState(); /* When you know actionA model type */ + simgrid::surf::Action::State stateActionA = actionA->getState(); /* When you know actionA model type */ + simgrid::surf::Action::State stateActionB = actionB->getState(); /* If you're unsure about it's model type */ + simgrid::surf::Action::State stateActionC = actionC->getState(); /* When you know actionA model type */ /* And just look at the state of these tasks */ XBT_INFO("actionA state: %s", string_action(stateActionA)); -- 2.20.1