Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cleanup the resource::Action::State::IGNORED thing
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 17 May 2018 20:43:44 +0000 (22:43 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 17 May 2018 20:46:27 +0000 (22:46 +0200)
Factorize stuff of CpuCas01Model and CpuTiModel into Model directly.
This way, Action::get_state() always knows in which set the action is.
No shit, no magic here.

include/simgrid/kernel/resource/Action.hpp
include/simgrid/kernel/resource/Model.hpp
src/kernel/resource/Action.cpp
src/surf/cpu_cas01.cpp
src/surf/cpu_cas01.hpp
src/surf/cpu_ti.cpp
src/surf/cpu_ti.hpp

index 72a9435..5c33f5b 100644 (file)
@@ -70,8 +70,8 @@ public:
     STARTED,  /**< Currently running */
     FAILED,   /**< either the resource failed, or the action was canceled */
     FINISHED, /**< Successfully completed  */
-    IGNORED /**< e.g. failure detectors, these infinite sleep actions that are put on resources which failure should be
-               notified */
+    IGNORED   /**< e.g. failure detectors: infinite sleep actions that are put on resources which failure should get
+                 noticed  */
   };
 
   enum class SuspendStates {
index 9a614ca..16e9a4f 100644 (file)
@@ -43,6 +43,9 @@ public:
   /** @brief Get the set of [actions](@ref Action) in *finished* state */
   Action::StateSet* get_finished_action_set() const { return finished_action_set_; }
 
+  /** @brief Get the set of [actions](@ref Action) in *ignored* state */
+  Action::StateSet* get_ignored_action_set() const { return ignored_action_set_; }
+
   /** @brief Get the set of modified [actions](@ref Action) */
   Action::ModifiedSet* get_modified_set() const;
 
@@ -92,6 +95,8 @@ private:
   Action::StateSet* started_action_set_  = new Action::StateSet(); /**< Started not done */
   Action::StateSet* failed_action_set_  = new Action::StateSet(); /**< Done with failure */
   Action::StateSet* finished_action_set_ = new Action::StateSet(); /**< Done successful */
+  Action::StateSet* ignored_action_set_  = new Action::StateSet(); /**< not considered (failure detectors?) */
+
   ActionHeap action_heap_;
 };
 
index 4fb398f..02aee24 100644 (file)
@@ -63,7 +63,9 @@ Action::State Action::get_state() const
     return Action::State::FAILED;
   if (state_set_ == model_->get_finished_action_set())
     return Action::State::FINISHED;
-  return Action::State::IGNORED;
+  if (state_set_ == model_->get_ignored_action_set())
+    return Action::State::IGNORED;
+  THROW_IMPOSSIBLE;
 }
 
 void Action::set_state(Action::State state)
@@ -82,6 +84,9 @@ void Action::set_state(Action::State state)
     case Action::State::FINISHED:
       state_set_ = model_->get_finished_action_set();
       break;
+    case Action::State::IGNORED:
+      state_set_ = model_->get_ignored_action_set();
+      break;
     default:
       state_set_ = nullptr;
       break;
index 926ff85..b069dc9 100644 (file)
@@ -188,12 +188,8 @@ CpuAction *CpuCas01::sleep(double duration)
   // FIXME: sleep variables should not consume 1.0 in System::expand()
   action->set_max_duration(duration);
   action->suspended_ = kernel::resource::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->get_state_set(), *action);
-    action->state_set_ = &static_cast<CpuCas01Model*>(get_model())->cpuRunningActionSetThatDoesNotNeedBeingChecked_;
-    action->get_state_set()->push_back(*action);
-  }
+  if (duration < 0) // NO_MAX_DURATION
+    action->set_state(simgrid::kernel::resource::Action::State::IGNORED);
 
   get_model()->get_maxmin_system()->update_variable_weight(action->get_variable(), 0.0);
   if (get_model()->get_update_algorithm() == kernel::resource::Model::UpdateAlgo::Lazy) { // remove action from the heap
index 99cbea6..0009db9 100644 (file)
@@ -27,7 +27,6 @@ public:
   ~CpuCas01Model() override;
 
   Cpu *createCpu(simgrid::s4u::Host *host, std::vector<double> *speedPerPstate, int core) override;
-  kernel::resource::Action::StateSet cpuRunningActionSetThatDoesNotNeedBeingChecked_;
 };
 
 /************
index 6ce9417..d15f1d2 100644 (file)
@@ -561,12 +561,8 @@ CpuAction *CpuTi::sleep(double duration)
 
   action->set_max_duration(duration);
   action->suspended_ = kernel::resource::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->get_state_set(), *action);
-    action->state_set_ = &static_cast<CpuTiModel*>(get_model())->runningActionSetThatDoesNotNeedBeingChecked_;
-    action->get_state_set()->push_back(*action);
-  }
+  if (duration < 0) // NO_MAX_DURATION
+    action->set_state(simgrid::kernel::resource::Action::State::IGNORED);
 
   action_set_.push_back(*action);
 
index b58b80e..a4f9184 100644 (file)
@@ -145,7 +145,6 @@ public:
   double next_occuring_event(double now) override;
   void update_actions_state(double now, double delta) override;
 
-  kernel::resource::Action::StateSet runningActionSetThatDoesNotNeedBeingChecked_;
   CpuTiList modified_cpus_;
 };