Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use references, and avoid disturbing expressions like &*it.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 21 Nov 2017 20:55:08 +0000 (21:55 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 22 Nov 2017 09:30:38 +0000 (10:30 +0100)
Also simplify the affected loops.

src/surf/cpu_interface.cpp
src/surf/cpu_ti.cpp
src/surf/network_cm02.cpp
src/surf/network_constant.cpp
src/surf/network_interface.cpp
src/surf/ptask_L07.cpp
src/surf/storage_n11.cpp
src/surf/surf_interface.cpp
teshsuite/surf/surf_usage/surf_usage.cpp

index 554c871..2c4e308 100644 (file)
@@ -44,13 +44,9 @@ void CpuModel::updateActionsStateLazy(double now, double /*delta*/)
     //defining the last timestamp that we can safely dump to trace file
     //without losing the event ascending order (considering all CPU's)
     double smaller = -1;
-    ActionList *actionSet = getRunningActionSet();
-    ActionList::iterator it(actionSet->begin());
-    ActionList::iterator itend(actionSet->end());
-    for (; it != itend; ++it) {
-      CpuAction *action = static_cast<CpuAction*>(&*it);
-      if (smaller < 0 || action->getLastUpdate() < smaller)
-        smaller = action->getLastUpdate();
+    for (Action const& action : *getRunningActionSet()) {
+      if (smaller < 0 || action.getLastUpdate() < smaller)
+        smaller = action.getLastUpdate();
     }
     if (smaller > 0) {
       TRACE_last_timestamp_to_dump = smaller;
@@ -60,30 +56,26 @@ void CpuModel::updateActionsStateLazy(double now, double /*delta*/)
 
 void CpuModel::updateActionsStateFull(double now, double delta)
 {
-  CpuAction *action = nullptr;
-  ActionList *running_actions = getRunningActionSet();
-  ActionList::iterator it(running_actions->begin());
-  ActionList::iterator itNext = it;
-  ActionList::iterator itend(running_actions->end());
-  for (; it != itend; it = itNext) {
-    ++itNext;
-    action = static_cast<CpuAction*>(&*it);
+  for (auto it = std::begin(*getRunningActionSet()); it != std::end(*getRunningActionSet());) {
+    CpuAction& action = static_cast<CpuAction&>(*it);
+    ++it; // increment iterator here since the following calls to action.finish() may invalidate it
     if (TRACE_is_enabled()) {
-      Cpu *cpu = static_cast<Cpu*> (lmm_constraint_id(lmm_get_cnst_from_var(getMaxminSystem(), action->getVariable(), 0)) );
+      Cpu* cpu =
+          static_cast<Cpu*>(lmm_constraint_id(lmm_get_cnst_from_var(getMaxminSystem(), action.getVariable(), 0)));
 
-      TRACE_surf_host_set_utilization(cpu->getCname(), action->getCategory(),
-                                      lmm_variable_getvalue(action->getVariable()), now - delta, delta);
+      TRACE_surf_host_set_utilization(cpu->getCname(), action.getCategory(),
+                                      lmm_variable_getvalue(action.getVariable()), now - delta, delta);
       TRACE_last_timestamp_to_dump = now - delta;
     }
 
-    action->updateRemains(lmm_variable_getvalue(action->getVariable()) * delta);
+    action.updateRemains(lmm_variable_getvalue(action.getVariable()) * delta);
 
-    if (action->getMaxDuration() != NO_MAX_DURATION)
-      action->updateMaxDuration(delta);
+    if (action.getMaxDuration() != NO_MAX_DURATION)
+      action.updateMaxDuration(delta);
 
-    if (((action->getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) ||
-        ((action->getMaxDuration() != NO_MAX_DURATION) && (action->getMaxDuration() <= 0))) {
-      action->finish(Action::State::done);
+    if (((action.getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action.getVariable()) > 0)) ||
+        ((action.getMaxDuration() != NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) {
+      action.finish(Action::State::done);
     }
   }
 }
index 942cfd2..55b0d23 100644 (file)
@@ -349,16 +349,14 @@ double CpuTiModel::nextOccuringEvent(double now)
 {
   double min_action_duration = -1;
 
-/* iterates over modified cpus to update share resources */
-  CpuTiList::iterator itend(modifiedCpu_->end());
-  CpuTiList::iterator it(modifiedCpu_->begin());
-  while (it != itend) {
-    CpuTi *ti = &*it;
-    ++it;
-    ti->updateActionsFinishTime(now);
+  /* iterates over modified cpus to update share resources */
+  for (auto it = std::begin(*modifiedCpu_); it != std::end(*modifiedCpu_);) {
+    CpuTi& ti = *it;
+    ++it; // increment iterator here since the following call to ti.updateActionsFinishTime() may invalidate it
+    ti.updateActionsFinishTime(now);
   }
 
-/* get the min next event if heap not empty */
+  /* get the min next event if heap not empty */
   if (not actionHeapIsEmpty())
     min_action_duration = actionHeapTopDate() - now;
 
@@ -452,15 +450,12 @@ void CpuTi::apply_event(tmgr_trace_event_t event, double value)
       double date = surf_get_clock();
 
       /* put all action running on cpu to failed */
-      ActionTiList::iterator itend(actionSet_->end());
-      for (ActionTiList::iterator it(actionSet_->begin()); it != itend; ++it) {
-        CpuTiAction *action = &*it;
-        if (action->getState() == Action::State::running
-         || action->getState() == Action::State::ready
-         || action->getState() == Action::State::not_in_the_system) {
-          action->setFinishTime(date);
-          action->setState(Action::State::failed);
-          action->heapRemove(model()->getActionHeap());
+      for (CpuTiAction& action : *actionSet_) {
+        if (action.getState() == Action::State::running || action.getState() == Action::State::ready ||
+            action.getState() == Action::State::not_in_the_system) {
+          action.setFinishTime(date);
+          action.setState(Action::State::failed);
+          action.heapRemove(model()->getActionHeap());
         }
       }
     }
@@ -473,66 +468,62 @@ void CpuTi::apply_event(tmgr_trace_event_t event, double value)
 
 void CpuTi::updateActionsFinishTime(double now)
 {
-  CpuTiAction *action;
   double sum_priority = 0.0;
   double total_area;
 
   /* update remaining amount of actions */
   updateRemainingAmount(now);
 
-  ActionTiList::iterator itend(actionSet_->end());
-  for (ActionTiList::iterator it(actionSet_->begin()); it != itend; ++it) {
-    action = &*it;
+  for (CpuTiAction const& action : *actionSet_) {
     /* action not running, skip it */
-    if (action->getStateSet() != surf_cpu_model_pm->getRunningActionSet())
+    if (action.getStateSet() != surf_cpu_model_pm->getRunningActionSet())
       continue;
 
     /* bogus priority, skip it */
-    if (action->getPriority() <= 0)
+    if (action.getPriority() <= 0)
       continue;
 
     /* action suspended, skip it */
-    if (action->suspended_ != 0)
+    if (action.suspended_ != 0)
       continue;
 
-    sum_priority += 1.0 / action->getPriority();
+    sum_priority += 1.0 / action.getPriority();
   }
   sumPriority_ = sum_priority;
 
-  for (ActionTiList::iterator it(actionSet_->begin()); it != itend; ++it) {
-    action = &*it;
+  for (CpuTiAction& action : *actionSet_) {
     double min_finish = -1;
     /* action not running, skip it */
-    if (action->getStateSet() !=  surf_cpu_model_pm->getRunningActionSet())
+    if (action.getStateSet() != surf_cpu_model_pm->getRunningActionSet())
       continue;
 
     /* verify if the action is really running on cpu */
-    if (action->suspended_ == 0 && action->getPriority() > 0) {
+    if (action.suspended_ == 0 && action.getPriority() > 0) {
       /* total area needed to finish the action. Used in trace integration */
-      total_area = (action->getRemains()) * sum_priority * action->getPriority();
+      total_area = (action.getRemains()) * sum_priority * action.getPriority();
 
       total_area /= speed_.peak;
 
-      action->setFinishTime(speedIntegratedTrace_->solve(now, total_area));
+      action.setFinishTime(speedIntegratedTrace_->solve(now, total_area));
       /* verify which event will happen before (max_duration or finish time) */
-      if (action->getMaxDuration() > NO_MAX_DURATION &&
-          action->getStartTime() + action->getMaxDuration() < action->getFinishTime())
-        min_finish = action->getStartTime() + action->getMaxDuration();
+      if (action.getMaxDuration() > NO_MAX_DURATION &&
+          action.getStartTime() + action.getMaxDuration() < action.getFinishTime())
+        min_finish = action.getStartTime() + action.getMaxDuration();
       else
-        min_finish = action->getFinishTime();
+        min_finish = action.getFinishTime();
     } else {
       /* put the max duration time on heap */
-      if (action->getMaxDuration() > NO_MAX_DURATION)
-        min_finish = action->getStartTime() + action->getMaxDuration();
+      if (action.getMaxDuration() > NO_MAX_DURATION)
+        min_finish = action.getStartTime() + action.getMaxDuration();
     }
     /* add in action heap */
     if (min_finish > NO_MAX_DURATION)
-      action->heapUpdate(model()->getActionHeap(), min_finish, NOTSET);
+      action.heapUpdate(model()->getActionHeap(), min_finish, NOTSET);
     else
-      action->heapRemove(model()->getActionHeap());
+      action.heapRemove(model()->getActionHeap());
 
     XBT_DEBUG("Update finish time: Cpu(%s) Action: %p, Start Time: %f Finish Time: %f Max duration %f", getCname(),
-              action, action->getStartTime(), action->getFinishTime(), action->getMaxDuration());
+              &action, action.getStartTime(), action.getFinishTime(), action.getMaxDuration());
   }
   /* remove from modified cpu */
   modified(false);
@@ -560,32 +551,30 @@ void CpuTi::updateRemainingAmount(double now)
   /* compute the integration area */
   double area_total = speedIntegratedTrace_->integrate(lastUpdate_, now) * speed_.peak;
   XBT_DEBUG("Flops total: %f, Last update %f", area_total, lastUpdate_);
-  ActionTiList::iterator itend(actionSet_->end());
-  for (ActionTiList::iterator it(actionSet_->begin()); it != itend; ++it) {
-    CpuTiAction *action = &*it;
+  for (CpuTiAction& action : *actionSet_) {
     /* action not running, skip it */
-    if (action->getStateSet() != model()->getRunningActionSet())
+    if (action.getStateSet() != model()->getRunningActionSet())
       continue;
 
     /* bogus priority, skip it */
-    if (action->getPriority() <= 0)
+    if (action.getPriority() <= 0)
       continue;
 
     /* action suspended, skip it */
-    if (action->suspended_ != 0)
+    if (action.suspended_ != 0)
       continue;
 
     /* action don't need update */
-    if (action->getStartTime() >= now)
+    if (action.getStartTime() >= now)
       continue;
 
     /* skip action that are finishing now */
-    if (action->getFinishTime() >= 0 && action->getFinishTime() <= now)
+    if (action.getFinishTime() >= 0 && action.getFinishTime() <= now)
       continue;
 
     /* update remaining */
-    action->updateRemains(area_total / (sumPriority_ * action->getPriority()));
-    XBT_DEBUG("Update remaining action(%p) remaining %f", action, action->getRemainsNoUpdate());
+    action.updateRemains(area_total / (sumPriority_ * action.getPriority()));
+    XBT_DEBUG("Update remaining action(%p) remaining %f", &action, action.getRemainsNoUpdate());
   }
   lastUpdate_ = now;
 }
index c7b6abc..943acb8 100644 (file)
@@ -210,51 +210,48 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
 
 void NetworkCm02Model::updateActionsStateFull(double now, double delta)
 {
-  ActionList *running_actions = getRunningActionSet();
-  ActionList::iterator it(running_actions->begin());
-  ActionList::iterator itend(running_actions->end());
-  while (it != itend) {
-    NetworkCm02Action *action = static_cast<NetworkCm02Action*> (&*it);
-    ++it;
-    XBT_DEBUG("Something happened to action %p", action);
-      double deltap = delta;
-      if (action->latency_ > 0) {
-        if (action->latency_ > deltap) {
-          double_update(&(action->latency_), deltap, sg_surf_precision);
-          deltap = 0.0;
-        } else {
-          double_update(&(deltap), action->latency_, sg_surf_precision);
-          action->latency_ = 0.0;
-        }
-        if (action->latency_ <= 0.0 && not action->isSuspended())
-          lmm_update_variable_weight(maxminSystem_, action->getVariable(), action->weight_);
-      }
-      if (TRACE_is_enabled()) {
-        int n = lmm_get_number_of_cnst_from_var(maxminSystem_, action->getVariable());
-        for (int i = 0; i < n; i++){
-          lmm_constraint_t constraint = lmm_get_cnst_from_var(maxminSystem_, action->getVariable(), i);
-
-          NetworkCm02Link* link = static_cast<NetworkCm02Link*>(lmm_constraint_id(constraint));
-          TRACE_surf_link_set_utilization(link->getCname(), action->getCategory(),
-                                          (lmm_variable_getvalue(action->getVariable()) *
-                                           lmm_get_cnst_weight_from_var(maxminSystem_, action->getVariable(), i)),
-                                          action->getLastUpdate(), now - action->getLastUpdate());
-        }
+  for (auto it = std::begin(*getRunningActionSet()); it != std::end(*getRunningActionSet());) {
+    NetworkCm02Action& action = static_cast<NetworkCm02Action&>(*it);
+    ++it; // increment iterator here since the following calls to action.finish() may invalidate it
+    XBT_DEBUG("Something happened to action %p", &action);
+    double deltap = delta;
+    if (action.latency_ > 0) {
+      if (action.latency_ > deltap) {
+        double_update(&action.latency_, deltap, sg_surf_precision);
+        deltap = 0.0;
+      } else {
+        double_update(&deltap, action.latency_, sg_surf_precision);
+        action.latency_ = 0.0;
       }
-      if (not lmm_get_number_of_cnst_from_var(maxminSystem_, action->getVariable())) {
-        /* There is actually no link used, hence an infinite bandwidth. This happens often when using models like
-         * vivaldi. In such case, just make sure that the action completes immediately.
-         */
-        action->updateRemains(action->getRemains());
+      if (action.latency_ <= 0.0 && not action.isSuspended())
+        lmm_update_variable_weight(maxminSystem_, action.getVariable(), action.weight_);
+    }
+    if (TRACE_is_enabled()) {
+      int n = lmm_get_number_of_cnst_from_var(maxminSystem_, action.getVariable());
+      for (int i = 0; i < n; i++) {
+        lmm_constraint_t constraint = lmm_get_cnst_from_var(maxminSystem_, action.getVariable(), i);
+
+        NetworkCm02Link* link = static_cast<NetworkCm02Link*>(lmm_constraint_id(constraint));
+        TRACE_surf_link_set_utilization(link->getCname(), action.getCategory(),
+                                        (lmm_variable_getvalue(action.getVariable()) *
+                                         lmm_get_cnst_weight_from_var(maxminSystem_, action.getVariable(), i)),
+                                        action.getLastUpdate(), now - action.getLastUpdate());
       }
-    action->updateRemains(lmm_variable_getvalue(action->getVariable()) * delta);
+    }
+    if (not lmm_get_number_of_cnst_from_var(maxminSystem_, action.getVariable())) {
+      /* There is actually no link used, hence an infinite bandwidth. This happens often when using models like
+       * vivaldi. In such case, just make sure that the action completes immediately.
+       */
+      action.updateRemains(action.getRemains());
+    }
+    action.updateRemains(lmm_variable_getvalue(action.getVariable()) * delta);
 
-    if (action->getMaxDuration() > NO_MAX_DURATION)
-      action->updateMaxDuration(delta);
+    if (action.getMaxDuration() > NO_MAX_DURATION)
+      action.updateMaxDuration(delta);
 
-    if (((action->getRemains() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) ||
-        ((action->getMaxDuration() > NO_MAX_DURATION) && (action->getMaxDuration() <= 0))) {
-      action->finish(Action::State::done);
+    if (((action.getRemains() <= 0) && (lmm_get_variable_weight(action.getVariable()) > 0)) ||
+        ((action.getMaxDuration() > NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) {
+      action.finish(Action::State::done);
     }
   }
 }
index 1f97acc..166d70e 100644 (file)
@@ -32,43 +32,33 @@ LinkImpl* NetworkConstantModel::createLink(const std::string& name, double bw, d
 double NetworkConstantModel::nextOccuringEvent(double /*now*/)
 {
   double min = -1.0;
-
-  ActionList* actionSet = getRunningActionSet();
-  ActionList::iterator it(actionSet->begin());
-  ActionList::iterator itend(actionSet->end());
-  for (; it != itend; ++it) {
-    NetworkConstantAction* action = static_cast<NetworkConstantAction*>(&*it);
-    if (action->latency_ > 0 && (min < 0 || action->latency_ < min))
-      min = action->latency_;
+  for (Action const& action : *getRunningActionSet()) {
+    const NetworkConstantAction& net_action = static_cast<const NetworkConstantAction&>(action);
+    if (net_action.latency_ > 0 && (min < 0 || net_action.latency_ < min))
+      min = net_action.latency_;
   }
-
   return min;
 }
 
 void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
 {
-  NetworkConstantAction* action = nullptr;
-  ActionList* actionSet         = getRunningActionSet();
-  ActionList::iterator it(actionSet->begin());
-  ActionList::iterator itNext = it;
-  ActionList::iterator itend(actionSet->end());
-  for (; it != itend; it = itNext) {
-    ++itNext;
-    action = static_cast<NetworkConstantAction*>(&*it);
-    if (action->latency_ > 0) {
-      if (action->latency_ > delta) {
-        double_update(&(action->latency_), delta, sg_surf_precision);
+  for (auto it = std::begin(*getRunningActionSet()); it != std::end(*getRunningActionSet());) {
+    NetworkConstantAction& action = static_cast<NetworkConstantAction&>(*it);
+    ++it; // increment iterator here since the following calls to action.finish() may invalidate it
+    if (action.latency_ > 0) {
+      if (action.latency_ > delta) {
+        double_update(&action.latency_, delta, sg_surf_precision);
       } else {
-        action->latency_ = 0.0;
+        action.latency_ = 0.0;
       }
     }
-    action->updateRemains(action->getCost() * delta / action->initialLatency_);
-    if (action->getMaxDuration() != NO_MAX_DURATION)
-      action->updateMaxDuration(delta);
+    action.updateRemains(action.getCost() * delta / action.initialLatency_);
+    if (action.getMaxDuration() != NO_MAX_DURATION)
+      action.updateMaxDuration(delta);
 
-    if ((action->getRemainsNoUpdate() <= 0) ||
-        ((action->getMaxDuration() != NO_MAX_DURATION) && (action->getMaxDuration() <= 0))) {
-      action->finish(Action::State::done);
+    if ((action.getRemainsNoUpdate() <= 0) ||
+        ((action.getMaxDuration() != NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) {
+      action.finish(Action::State::done);
     }
   }
 }
index 54c4bb8..f88a72d 100644 (file)
@@ -89,10 +89,10 @@ namespace simgrid {
     {
       double minRes = Model::nextOccuringEventFull(now);
 
-      for (auto it(getRunningActionSet()->begin()); it != getRunningActionSet()->end(); it++) {
-        NetworkAction *action = static_cast<NetworkAction*>(&*it);
-        if (action->latency_ > 0)
-          minRes = (minRes < 0) ? action->latency_ : std::min(minRes, action->latency_);
+      for (Action const& action : *getRunningActionSet()) {
+        const NetworkAction& net_action = static_cast<const NetworkAction&>(action);
+        if (net_action.latency_ > 0)
+          minRes = (minRes < 0) ? net_action.latency_ : std::min(minRes, net_action.latency_);
       }
 
       XBT_DEBUG("Min of share resources %f", minRes);
index bc65a38..7a3c22b 100644 (file)
@@ -76,13 +76,11 @@ NetworkL07Model::~NetworkL07Model()
 double HostL07Model::nextOccuringEvent(double now)
 {
   double min = HostModel::nextOccuringEventFull(now);
-  ActionList::iterator it(getRunningActionSet()->begin());
-  ActionList::iterator itend(getRunningActionSet()->end());
-  for (; it != itend; ++it) {
-    L07Action *action = static_cast<L07Action*>(&*it);
-    if (action->latency_ > 0 && (min < 0 || action->latency_ < min)) {
-      min = action->latency_;
-      XBT_DEBUG("Updating min with %p (start %f): %f", action, action->getStartTime(), min);
+  for (Action const& action : *getRunningActionSet()) {
+    const L07Action& net_action = static_cast<const L07Action&>(action);
+    if (net_action.latency_ > 0 && (min < 0 || net_action.latency_ < min)) {
+      min = net_action.latency_;
+      XBT_DEBUG("Updating min with %p (start %f): %f", &net_action, net_action.getStartTime(), min);
     }
   }
   XBT_DEBUG("min value: %f", min);
@@ -90,36 +88,30 @@ double HostL07Model::nextOccuringEvent(double now)
   return min;
 }
 
-void HostL07Model::updateActionsState(double /*now*/, double delta) {
-
-  L07Action *action;
-  ActionList *actionSet = getRunningActionSet();
-  ActionList::iterator it(actionSet->begin());
-  ActionList::iterator itNext = it;
-  ActionList::iterator itend(actionSet->end());
-
-  for (; it != itend; it = itNext) {
-    ++itNext;
-    action = static_cast<L07Action*>(&*it);
-    if (action->latency_ > 0) {
-      if (action->latency_ > delta) {
-        double_update(&(action->latency_), delta, sg_surf_precision);
+void HostL07Model::updateActionsState(double /*now*/, double delta)
+{
+  for (auto it = std::begin(*getRunningActionSet()); it != std::end(*getRunningActionSet());) {
+    L07Action& action = static_cast<L07Action&>(*it);
+    ++it; // increment iterator here since the following calls to action.finish() may invalidate it
+    if (action.latency_ > 0) {
+      if (action.latency_ > delta) {
+        double_update(&(action.latency_), delta, sg_surf_precision);
       } else {
-        action->latency_ = 0.0;
+        action.latency_ = 0.0;
       }
-      if ((action->latency_ <= 0.0) && (action->isSuspended() == 0)) {
-        action->updateBound();
-        lmm_update_variable_weight(maxminSystem_, action->getVariable(), 1.0);
+      if ((action.latency_ <= 0.0) && (action.isSuspended() == 0)) {
+        action.updateBound();
+        lmm_update_variable_weight(maxminSystem_, action.getVariable(), 1.0);
       }
     }
-    XBT_DEBUG("Action (%p) : remains (%g) updated by %g.",
-           action, action->getRemains(), lmm_variable_getvalue(action->getVariable()) * delta);
-    action->updateRemains(lmm_variable_getvalue(action->getVariable()) * delta);
+    XBT_DEBUG("Action (%p) : remains (%g) updated by %g.", &action, action.getRemains(),
+              lmm_variable_getvalue(action.getVariable()) * delta);
+    action.updateRemains(lmm_variable_getvalue(action.getVariable()) * delta);
 
-    if (action->getMaxDuration() > NO_MAX_DURATION)
-      action->updateMaxDuration(delta);
+    if (action.getMaxDuration() > NO_MAX_DURATION)
+      action.updateMaxDuration(delta);
 
-    XBT_DEBUG("Action (%p) : remains (%g).", action, action->getRemains());
+    XBT_DEBUG("Action (%p) : remains (%g).", &action, action.getRemains());
 
     /* In the next if cascade, the action can be finished either because:
      *  - The amount of remaining work reached 0
@@ -127,22 +119,22 @@ void HostL07Model::updateActionsState(double /*now*/, double delta) {
      * If it's not done, it may have failed.
      */
 
-    if (((action->getRemains() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) ||
-        ((action->getMaxDuration() > NO_MAX_DURATION) && (action->getMaxDuration() <= 0))) {
-      action->finish(Action::State::done);
+    if (((action.getRemains() <= 0) && (lmm_get_variable_weight(action.getVariable()) > 0)) ||
+        ((action.getMaxDuration() > NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) {
+      action.finish(Action::State::done);
     } else {
       /* Need to check that none of the model has failed */
       int i = 0;
-      lmm_constraint_t cnst = lmm_get_cnst_from_var(maxminSystem_, action->getVariable(), i);
+      lmm_constraint_t cnst = lmm_get_cnst_from_var(maxminSystem_, action.getVariable(), i);
       while (cnst != nullptr) {
         i++;
         void *constraint_id = lmm_constraint_id(cnst);
         if (static_cast<simgrid::surf::Resource*>(constraint_id)->isOff()) {
-          XBT_DEBUG("Action (%p) Failed!!", action);
-          action->finish(Action::State::failed);
+          XBT_DEBUG("Action (%p) Failed!!", &action);
+          action.finish(Action::State::failed);
           break;
         }
-        cnst = lmm_get_cnst_from_var(maxminSystem_, action->getVariable(), i);
+        cnst = lmm_get_cnst_from_var(maxminSystem_, action.getVariable(), i);
       }
     }
   }
index 2bbfd74..54f2847 100644 (file)
@@ -75,28 +75,24 @@ double StorageN11Model::nextOccuringEvent(double now)
 
 void StorageN11Model::updateActionsState(double /*now*/, double delta)
 {
-  ActionList *actionSet = getRunningActionSet();
-  ActionList::iterator it(actionSet->begin());
-  ActionList::iterator itend(actionSet->end());
-  while (it != itend) {
-    StorageAction *action = static_cast<StorageAction*>(&*it);
-    ++it;
-    double current_progress = lrint(lmm_variable_getvalue(action->getVariable()) * delta);
-
-    action->updateRemains(current_progress);
-    if (action->type_ == WRITE) {
-      action->storage_->usedSize_ += current_progress;
+  for (auto it = std::begin(*getRunningActionSet()); it != std::end(*getRunningActionSet());) {
+    StorageAction& action = static_cast<StorageAction&>(*it);
+    ++it; // increment iterator here since the following calls to action.finish() may invalidate it
+    double current_progress = lrint(lmm_variable_getvalue(action.getVariable()) * delta);
+    action.updateRemains(current_progress);
+    if (action.type_ == WRITE) {
+      action.storage_->usedSize_ += current_progress;
     }
 
-    if (action->getMaxDuration() > NO_MAX_DURATION)
-      action->updateMaxDuration(delta);
+    if (action.getMaxDuration() > NO_MAX_DURATION)
+      action.updateMaxDuration(delta);
 
-    if (action->getRemainsNoUpdate() > 0 && lmm_get_variable_weight(action->getVariable()) > 0 &&
-        action->storage_->usedSize_ == action->storage_->getSize()) {
-      action->finish(Action::State::failed);
-    } else if (((action->getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) ||
-               ((action->getMaxDuration() > NO_MAX_DURATION) && (action->getMaxDuration() <= 0))) {
-      action->finish(Action::State::done);
+    if (action.getRemainsNoUpdate() > 0 && lmm_get_variable_weight(action.getVariable()) > 0 &&
+        action.storage_->usedSize_ == action.storage_->getSize()) {
+      action.finish(Action::State::failed);
+    } else if (((action.getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action.getVariable()) > 0)) ||
+               ((action.getMaxDuration() > NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) {
+      action.finish(Action::State::done);
     }
   }
 }
index 999fca9..67c6b6b 100644 (file)
@@ -464,22 +464,21 @@ double Model::nextOccuringEventFull(double /*now*/) {
 
   double min = -1;
 
-  for (auto it(getRunningActionSet()->begin()); it != getRunningActionSet()->end(); ++it) {
-    Action *action = &*it;
-    double value = lmm_variable_getvalue(action->getVariable());
+  for (Action& action : *getRunningActionSet()) {
+    double value = lmm_variable_getvalue(action.getVariable());
     if (value > 0) {
-      if (action->getRemains() > 0)
-        value = action->getRemainsNoUpdate() / value;
+      if (action.getRemains() > 0)
+        value = action.getRemainsNoUpdate() / value;
       else
         value = 0.0;
       if (min < 0 || value < min) {
         min = value;
-        XBT_DEBUG("Updating min (value) with %p: %f", action, min);
+        XBT_DEBUG("Updating min (value) with %p: %f", &action, min);
       }
     }
-    if ((action->getMaxDuration() >= 0) && (min<0 || action->getMaxDuration() < min)) {
-      min = action->getMaxDuration();
-      XBT_DEBUG("Updating min (duration) with %p: %f", action, min);
+    if ((action.getMaxDuration() >= 0) && (min < 0 || action.getMaxDuration() < min)) {
+      min = action.getMaxDuration();
+      XBT_DEBUG("Updating min (duration) with %p: %f", &action, min);
     }
   }
   XBT_DEBUG("min value : %f", min);
index 57b800a..333ecff 100644 (file)
@@ -68,34 +68,34 @@ int main(int argc, char **argv)
 
     simgrid::surf::ActionList* action_list = surf_cpu_model_pm->getFailedActionSet();
     while (not action_list->empty()) {
-      simgrid::surf::Action* action = &*action_list->begin();
+      simgrid::surf::Action& action = action_list->front();
       XBT_INFO("   CPU Failed action");
-      XBT_DEBUG("\t * Failed : %p", action);
-      action->unref();
+      XBT_DEBUG("\t * Failed : %p", &action);
+      action.unref();
     }
 
     action_list = surf_cpu_model_pm->getDoneActionSet();
     while (not action_list->empty()) {
-      simgrid::surf::Action* action = &*action_list->begin();
+      simgrid::surf::Action& action = action_list->front();
       XBT_INFO("   CPU Done action");
-      XBT_DEBUG("\t * Done : %p", action);
-      action->unref();
+      XBT_DEBUG("\t * Done : %p", &action);
+      action.unref();
     }
 
     action_list = surf_network_model->getFailedActionSet();
     while (not action_list->empty()) {
-      simgrid::surf::Action* action = &*action_list->begin();
+      simgrid::surf::Action& action = action_list->front();
       XBT_INFO("   Network Failed action");
-      XBT_DEBUG("\t * Failed : %p", action);
-      action->unref();
+      XBT_DEBUG("\t * Failed : %p", &action);
+      action.unref();
     }
 
     action_list = surf_network_model->getDoneActionSet();
     while (not action_list->empty()) {
-      simgrid::surf::Action* action = &*action_list->begin();
+      simgrid::surf::Action& action = action_list->front();
       XBT_INFO("   Network Done action");
-      XBT_DEBUG("\t * Done : %p", action);
-      action->unref();
+      XBT_DEBUG("\t * Done : %p", &action);
+      action.unref();
     }
 
   } while ((surf_network_model->getRunningActionSet()->size() ||