Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
use an enum class for surf::Action type
authorMartin Quinson <martin.quinson@loria.fr>
Sat, 10 Mar 2018 02:23:09 +0000 (03:23 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sat, 10 Mar 2018 02:23:09 +0000 (03:23 +0100)
src/surf/cpu_ti.cpp
src/surf/network_cm02.cpp
src/surf/surf_interface.cpp
src/surf/surf_interface.hpp

index 462b806..6015f1d 100644 (file)
@@ -507,7 +507,7 @@ void CpuTi::updateActionsFinishTime(double now)
     }
     /* add in action heap */
     if (min_finish > NO_MAX_DURATION)
-      action.heapUpdate(model()->getActionHeap(), min_finish, NOTSET);
+      action.heapUpdate(model()->getActionHeap(), min_finish, Action::Type::NOTSET);
     else
       action.heapRemove(model()->getActionHeap());
 
@@ -693,7 +693,7 @@ void CpuTiAction::setMaxDuration(double duration)
     min_finish = getFinishTime();
 
   /* add in action heap */
-  heapUpdate(getModel()->getActionHeap(), min_finish, NOTSET);
+  heapUpdate(getModel()->getActionHeap(), min_finish, Action::Type::NOTSET);
 
   XBT_OUT();
 }
index a8dbb4b..c440d22 100644 (file)
@@ -191,16 +191,16 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
     }
 
     // if I am wearing a latency hat
-    if (action->getHat() == LATENCY) {
+    if (action->getHat() == Action::Type::LATENCY) {
       XBT_DEBUG("Latency paid for action %p. Activating", action);
       maxminSystem_->update_variable_weight(action->getVariable(), action->weight_);
       action->heapRemove(getActionHeap());
       action->refreshLastUpdate();
 
         // if I am wearing a max_duration or normal hat
-    } else if (action->getHat() == MAX_DURATION || action->getHat() == NORMAL) {
-        // no need to communicate anymore
-        // assume that flows that reached max_duration have remaining of 0
+    } else if (action->getHat() == Action::Type::MAX_DURATION || action->getHat() == Action::Type::NORMAL) {
+      // no need to communicate anymore
+      // assume that flows that reached max_duration have remaining of 0
       XBT_DEBUG("Action %p finished", action);
       action->setRemains(0);
       action->finish(Action::State::done);
@@ -312,7 +312,8 @@ 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(getActionHeap(), action->latency_ + action->getLastUpdate(), route.empty() ? NORMAL : LATENCY);
+      action->heapInsert(getActionHeap(), action->latency_ + action->getLastUpdate(),
+                         route.empty() ? Action::Type::NORMAL : Action::Type::LATENCY);
     }
   } else
     action->setVariable(maxminSystem_->variable_new(action, 1.0, -1.0, constraints_per_variable));
index b69e677..3549820 100644 (file)
@@ -413,7 +413,7 @@ double Model::nextOccuringEventLazy(double now)
       continue;
 
     /* bogus priority, skip it */
-    if (action->getPriority() <= 0 || action->getHat()==LATENCY)
+    if (action->getPriority() <= 0 || action->getHat() == Action::Type::LATENCY)
       continue;
 
     action->updateRemainingLazy(now);
@@ -445,7 +445,7 @@ double Model::nextOccuringEventLazy(double now)
         action->getMaxDuration());
 
     if (min > -1) {
-      action->heapUpdate(actionHeap_, min, max_dur_flag ? MAX_DURATION : NORMAL);
+      action->heapUpdate(actionHeap_, min, max_dur_flag ? Action::Type::MAX_DURATION : Action::Type::NORMAL);
       XBT_DEBUG("Insert at heap action(%p) min %f now %f", action, min, now);
     } else
       DIE_IMPOSSIBLE;
@@ -755,7 +755,7 @@ bool Action::isSuspended()
  * LATENCY = this is a heap entry to warn us when the latency is payed
  * MAX_DURATION =this is a heap entry to warn us when the max_duration limit is reached
  */
-void Action::heapInsert(heap_type& heap, double key, enum heap_action_type hat)
+void Action::heapInsert(heap_type& heap, double key, Action::Type hat)
 {
   hat_ = hat;
   heapHandle_ = heap.emplace(std::make_pair(key, this));
@@ -763,14 +763,14 @@ void Action::heapInsert(heap_type& heap, double key, enum heap_action_type hat)
 
 void Action::heapRemove(heap_type& heap)
 {
-  hat_ = NOTSET;
+  hat_ = Action::Type::NOTSET;
   if (heapHandle_) {
     heap.erase(*heapHandle_);
     clearHeapHandle();
   }
 }
 
-void Action::heapUpdate(heap_type& heap, double key, enum heap_action_type hat)
+void Action::heapUpdate(heap_type& heap, double key, Action::Type hat)
 {
   hat_ = hat;
   if (heapHandle_) {
index 8b16ee0..34599d2 100644 (file)
@@ -80,17 +80,6 @@ extern XBT_PRIVATE simgrid::xbt::signal<void()> surfExitCallbacks;
 
 int XBT_PRIVATE __surf_is_absolute_file_path(const char *file_path);
 
-/***********
- * Classes *
- ***********/
-
-enum heap_action_type{
-  LATENCY = 100,
-  MAX_DURATION,
-  NORMAL,
-  NOTSET
-};
-
 /**********
  * Action *
  **********/
@@ -135,6 +124,8 @@ public:
     sleeping
   };
 
+  enum class Type { LATENCY = 100, MAX_DURATION, NORMAL, NOTSET };
+
   /**
    * @brief Action constructor
    *
@@ -268,14 +259,14 @@ private:
   double lastUpdate_                                  = 0;
   double lastValue_                                   = 0;
   lmm_variable_t variable_                            = nullptr;
-  enum heap_action_type hat_                          = NOTSET;
+  Action::Type hat_                                   = Action::Type::NOTSET;
   boost::optional<heap_type::handle_type> heapHandle_ = boost::none;
 
 public:
   virtual void updateRemainingLazy(double now) { THROW_IMPOSSIBLE; };
-  void heapInsert(heap_type& heap, double key, enum heap_action_type hat);
+  void heapInsert(heap_type & heap, double key, Action::Type hat);
   void heapRemove(heap_type& heap);
-  void heapUpdate(heap_type& heap, double key, enum heap_action_type hat);
+  void heapUpdate(heap_type & heap, double key, Action::Type hat);
   void clearHeapHandle() { heapHandle_ = boost::none; }
   lmm_variable_t getVariable() const { return variable_; }
   void setVariable(lmm_variable_t var) { variable_ = var; }
@@ -283,7 +274,7 @@ public:
   void refreshLastUpdate() {lastUpdate_ = surf_get_clock();}
   double getLastValue() const { return lastValue_; }
   void setLastValue(double val) { lastValue_ = val; }
-  enum heap_action_type getHat() const { return hat_; }
+  Action::Type getHat() const { return hat_; }
   bool is_linked() const { return action_lmm_hook.is_linked(); }
 protected:
   Action::SuspendStates suspended_ = Action::SuspendStates::not_suspended;