Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use simgrid::xbt::intrusive_erase().
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 4 Dec 2017 21:18:04 +0000 (22:18 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 4 Dec 2017 22:41:13 +0000 (23:41 +0100)
src/kernel/lmm/fair_bottleneck.cpp
src/kernel/lmm/maxmin.cpp
src/kernel/lmm/maxmin.hpp
src/simix/ActorImpl.cpp
src/surf/cpu_cas01.cpp
src/surf/cpu_ti.cpp
src/surf/network_ns3.cpp
src/surf/ptask_L07.cpp
src/surf/storage_n11.cpp
src/surf/surf_interface.cpp

index 5ff0ef2..71de3e7 100644 (file)
@@ -11,6 +11,7 @@
 #include <cfloat>
 #include <cmath>
 #include <cstdlib>
+#include <xbt/utility.hpp>
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_maxmin);
 #define SHOW_EXPR_G(expr) XBT_DEBUG(#expr " = %g", expr);
@@ -132,7 +133,7 @@ void simgrid::kernel::lmm::bottleneck_solve(lmm_system_t sys)
             break;
           if (elem.consumption_weight > 0 && elem.variable->saturated_variable_set_hook.is_linked()) {
             XBT_DEBUG("\t\tGet rid of variable %p", elem.variable);
-            var_list.erase(var_list.iterator_to(*elem.variable));
+            simgrid::xbt::intrusive_erase(var_list, *elem.variable);
           }
         }
       } else {
index f9c28c9..0c1fe8a 100644 (file)
@@ -10,6 +10,7 @@
 #include "xbt/log.h"
 #include "xbt/mallocator.h"
 #include "xbt/sysdep.h"
+#include "xbt/utility.hpp"
 #include <algorithm>
 #include <cmath>
 #include <cstdlib>
@@ -121,18 +122,12 @@ void s_lmm_system_t::var_free(lmm_variable_t var)
   for (s_lmm_element_t& elem : var->cnsts) {
     if (var->sharing_weight > 0)
       elem.decrease_concurrency();
-    if (elem.enabled_element_set_hook.is_linked()) {
-      auto& set = elem.constraint->enabled_element_set;
-      set.erase(set.iterator_to(elem));
-    }
-    if (elem.disabled_element_set_hook.is_linked()) {
-      auto& set = elem.constraint->disabled_element_set;
-      set.erase(set.iterator_to(elem));
-    }
-    if (elem.active_element_set_hook.is_linked()) {
-      auto& set = elem.constraint->active_element_set;
-      set.erase(set.iterator_to(elem));
-    }
+    if (elem.enabled_element_set_hook.is_linked())
+      simgrid::xbt::intrusive_erase(elem.constraint->enabled_element_set, elem);
+    if (elem.disabled_element_set_hook.is_linked())
+      simgrid::xbt::intrusive_erase(elem.constraint->disabled_element_set, elem);
+    if (elem.active_element_set_hook.is_linked())
+      simgrid::xbt::intrusive_erase(elem.constraint->active_element_set, elem);
     int nelements = elem.constraint->enabled_element_set.size() + elem.constraint->disabled_element_set.size();
     if (nelements == 0)
       make_constraint_inactive(elem.constraint);
@@ -770,11 +765,10 @@ void s_lmm_system_t::enable_var(lmm_variable_t var)
   // Enabling the variable, move var to list head. Subtlety is: here, we need to call update_modified_set AFTER
   // moving at least one element of var.
 
-  variable_set.erase(variable_set.iterator_to(*var));
+  simgrid::xbt::intrusive_erase(variable_set, *var);
   variable_set.push_front(*var);
   for (s_lmm_element_t& elem : var->cnsts) {
-    auto& set = elem.constraint->disabled_element_set;
-    set.erase(set.iterator_to(elem));
+    simgrid::xbt::intrusive_erase(elem.constraint->disabled_element_set, elem);
     elem.constraint->enabled_element_set.push_front(elem);
     elem.increase_concurrency();
   }
@@ -791,18 +785,15 @@ void s_lmm_system_t::disable_var(lmm_variable_t var)
   xbt_assert(not var->staged_weight, "Staged weight should have been cleared");
   // Disabling the variable, move to var to list tail. Subtlety is: here, we need to call update_modified_set
   // BEFORE moving the last element of var.
-  variable_set.erase(variable_set.iterator_to(*var));
+  simgrid::xbt::intrusive_erase(variable_set, *var);
   variable_set.push_back(*var);
   if (not var->cnsts.empty())
     update_modified_set(var->cnsts[0].constraint);
   for (s_lmm_element_t& elem : var->cnsts) {
-    auto& set = elem.constraint->enabled_element_set;
-    set.erase(set.iterator_to(elem));
+    simgrid::xbt::intrusive_erase(elem.constraint->enabled_element_set, elem);
     elem.constraint->disabled_element_set.push_back(elem);
-    if (elem.active_element_set_hook.is_linked()) {
-      auto& set = elem.constraint->active_element_set;
-      set.erase(set.iterator_to(elem));
-    }
+    if (elem.active_element_set_hook.is_linked())
+      simgrid::xbt::intrusive_erase(elem.constraint->active_element_set, elem);
     elem.decrease_concurrency();
   }
 
index 3fc501f..1d36422 100644 (file)
@@ -12,6 +12,7 @@
 #include "xbt/asserts.h"
 #include "xbt/mallocator.h"
 #include "xbt/misc.h"
+#include "xbt/utility.hpp"
 #include <boost/intrusive/list.hpp>
 #include <cmath>
 #include <limits>
@@ -437,10 +438,8 @@ inline void s_lmm_element_t::make_active()
 }
 inline void s_lmm_element_t::make_inactive()
 {
-  if (active_element_set_hook.is_linked()) {
-    auto& set = constraint->active_element_set;
-    set.erase(set.iterator_to(*this));
-  }
+  if (active_element_set_hook.is_linked())
+    simgrid::xbt::intrusive_erase(constraint->active_element_set, *this);
 }
 
 /**
@@ -555,9 +554,9 @@ private:
   void remove_variable(lmm_variable_t var)
   {
     if (var->variable_set_hook.is_linked())
-      variable_set.erase(variable_set.iterator_to(*var));
+      simgrid::xbt::intrusive_erase(variable_set, *var);
     if (var->saturated_variable_set_hook.is_linked())
-      saturated_variable_set.erase(saturated_variable_set.iterator_to(*var));
+      simgrid::xbt::intrusive_erase(saturated_variable_set, *var);
   }
   void make_constraint_active(lmm_constraint_t cnst)
   {
@@ -567,9 +566,9 @@ private:
   void make_constraint_inactive(lmm_constraint_t cnst)
   {
     if (cnst->active_constraint_set_hook.is_linked())
-      active_constraint_set.erase(active_constraint_set.iterator_to(*cnst));
+      simgrid::xbt::intrusive_erase(active_constraint_set, *cnst);
     if (cnst->modified_constraint_set_hook.is_linked())
-      modified_constraint_set.erase(modified_constraint_set.iterator_to(*cnst));
+      simgrid::xbt::intrusive_erase(modified_constraint_set, *cnst);
   }
 
   void enable_var(lmm_variable_t var);
index 3effdcb..2295dd3 100644 (file)
@@ -15,6 +15,7 @@
 #include "xbt/functional.hpp"
 #include "xbt/log.h"
 #include "xbt/sysdep.h"
+#include "xbt/utility.hpp"
 
 #include "simgrid/s4u/Host.hpp"
 
@@ -112,10 +113,8 @@ void SIMIX_process_cleanup(smx_actor_t process)
 
   XBT_DEBUG("%p should not be run anymore",process);
   simix_global->process_list.erase(process->pid);
-  if (process->host && process->host_process_list_hook.is_linked()) {
-    auto& list = process->host->extension<simgrid::simix::Host>()->process_list;
-    list.erase(list.iterator_to(*process));
-  }
+  if (process->host && process->host_process_list_hook.is_linked())
+    simgrid::xbt::intrusive_erase(process->host->extension<simgrid::simix::Host>()->process_list, *process);
   xbt_swag_insert(process, simix_global->process_to_destroy);
   process->context->iwannadie = 0;
 
@@ -600,8 +599,7 @@ void SIMIX_process_killall(smx_actor_t issuer, int reset_pid)
 void SIMIX_process_change_host(smx_actor_t process, sg_host_t dest)
 {
   xbt_assert((process != nullptr), "Invalid parameters");
-  auto& list = process->host->extension<simgrid::simix::Host>()->process_list;
-  list.erase(list.iterator_to(*process));
+  simgrid::xbt::intrusive_erase(process->host->extension<simgrid::simix::Host>()->process_list, *process);
   process->host = dest;
   dest->extension<simgrid::simix::Host>()->process_list.push_back(*process);
 }
index bfa4e53..27ccc86 100644 (file)
@@ -8,6 +8,7 @@
 #include "cpu_ti.hpp"
 #include "simgrid/sg_config.h"
 #include "src/kernel/lmm/maxmin.hpp"
+#include "xbt/utility.hpp"
 #include <algorithm>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_cas, surf_cpu, "Logging specific to the SURF CPU IMPROVED module");
@@ -184,7 +185,7 @@ CpuAction *CpuCas01::sleep(double duration)
   action->suspended_ = 2;
   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 */
-    action->getStateSet()->erase(action->getStateSet()->iterator_to(*action));
+    simgrid::xbt::intrusive_erase(*action->getStateSet(), *action);
     action->stateSet_ = static_cast<CpuCas01Model*>(model())->p_cpuRunningActionSetThatDoesNotNeedBeingChecked;
     action->getStateSet()->push_back(*action);
   }
index d65cf33..d36dff6 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "cpu_ti.hpp"
 #include "src/surf/trace_mgr.hpp"
+#include "xbt/utility.hpp"
 #include <algorithm>
 
 #ifndef SURF_MODEL_CPUTI_H_
@@ -602,11 +603,10 @@ CpuAction *CpuTi::sleep(double duration)
   action->setMaxDuration(duration);
   action->suspended_ = 2;
   if (duration == NO_MAX_DURATION) {
-   /* Move to the *end* of the corresponding action set. This convention
-      is used to speed up update_resource_state  */
-  action->getStateSet()->erase(action->getStateSet()->iterator_to(*action));
-  action->stateSet_ = static_cast<CpuTiModel*>(model())->runningActionSetThatDoesNotNeedBeingChecked_;
-  action->getStateSet()->push_back(*action);
+    /* 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);
+    action->stateSet_ = static_cast<CpuTiModel*>(model())->runningActionSetThatDoesNotNeedBeingChecked_;
+    action->getStateSet()->push_back(*action);
   }
 
   actionSet_->push_back(*action);
@@ -622,9 +622,8 @@ void CpuTi::modified(bool modified){
       modifiedCpu->push_back(*this);
     }
   } else {
-    if (cpu_ti_hook.is_linked()) {
-      modifiedCpu->erase(modifiedCpu->iterator_to(*this));
-    }
+    if (cpu_ti_hook.is_linked())
+      simgrid::xbt::intrusive_erase(*modifiedCpu, *this);
   }
 }
 
@@ -650,10 +649,10 @@ int CpuTiAction::unref()
   refcount_--;
   if (not refcount_) {
     if (action_hook.is_linked())
-      getStateSet()->erase(getStateSet()->iterator_to(*this));
+      simgrid::xbt::intrusive_erase(*getStateSet(), *this);
     /* remove from action_set */
     if (action_ti_hook.is_linked())
-      cpu_->actionSet_->erase(cpu_->actionSet_->iterator_to(*this));
+      simgrid::xbt::intrusive_erase(*cpu_->actionSet_, *this);
     /* remove from heap */
     heapRemove(getModel()->getActionHeap());
     cpu_->modified(true);
index 7c30095..85aab98 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "xbt/config.hpp"
 #include "xbt/string.hpp"
+#include "xbt/utility.hpp"
 
 #include "ns3/core-module.h"
 #include "ns3/node.h"
@@ -312,7 +313,7 @@ int NetworkNS3Action::unref()
   refcount_--;
   if (not refcount_) {
     if (action_hook.is_linked())
-      stateSet_->erase(stateSet_->iterator_to(*this));
+      simgrid::xbt::intrusive_erase(*stateSet_, *this);
     XBT_DEBUG ("Removing action %p", this);
     delete this;
     return 1;
index d94f6fb..0c026b4 100644 (file)
@@ -12,6 +12,7 @@
 #include "ptask_L07.hpp"
 
 #include "cpu_interface.hpp"
+#include "xbt/utility.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_host);
 XBT_LOG_EXTERNAL_CATEGORY(xbt_cfg);
@@ -420,7 +421,7 @@ int L07Action::unref()
   refcount_--;
   if (not refcount_) {
     if (action_hook.is_linked())
-      stateSet_->erase(stateSet_->iterator_to(*this));
+      simgrid::xbt::intrusive_erase(*stateSet_, *this);
     if (getVariable())
       getModel()->getMaxminSystem()->variable_free(getVariable());
     delete this;
index 340c601..130879d 100644 (file)
@@ -7,6 +7,7 @@
 #include "simgrid/s4u/Engine.hpp"
 #include "src/kernel/lmm/maxmin.hpp"
 #include "src/kernel/routing/NetPoint.hpp"
+#include "xbt/utility.hpp"
 #include <cmath> /*ceil*/
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_storage);
@@ -143,7 +144,7 @@ int StorageN11Action::unref()
   refcount_--;
   if (not refcount_) {
     if (action_hook.is_linked())
-      stateSet_->erase(stateSet_->iterator_to(*this));
+      simgrid::xbt::intrusive_erase(*stateSet_, *this);
     if (getVariable())
       getModel()->getMaxminSystem()->variable_free(getVariable());
     xbt_free(getCategory());
index cb5ed0e..f61c84f 100644 (file)
@@ -10,6 +10,7 @@
 #include "src/instr/instr_private.hpp" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
 #include "src/kernel/routing/NetPoint.hpp"
 #include "src/surf/HostImpl.hpp"
+#include "xbt/utility.hpp"
 
 #include <fstream>
 #include <set>
@@ -622,7 +623,7 @@ Action::State Action::getState() const
 
 void Action::setState(Action::State state)
 {
-  stateSet_->erase(stateSet_->iterator_to(*this));
+  simgrid::xbt::intrusive_erase(*stateSet_, *this);
   switch (state) {
   case Action::State::ready:
     stateSet_ = model_->getReadyActionSet();
@@ -691,7 +692,7 @@ void Action::cancel(){
   setState(Action::State::failed);
   if (getModel()->getUpdateMechanism() == UM_LAZY) {
     if (action_lmm_hook.is_linked())
-      getModel()->getModifiedSet()->erase(getModel()->getModifiedSet()->iterator_to(*this));
+      simgrid::xbt::intrusive_erase(*getModel()->getModifiedSet(), *this);
     heapRemove(getModel()->getActionHeap());
   }
 }
@@ -700,14 +701,14 @@ int Action::unref(){
   refcount_--;
   if (not refcount_) {
     if (action_hook.is_linked())
-      stateSet_->erase(stateSet_->iterator_to(*this));
+      simgrid::xbt::intrusive_erase(*stateSet_, *this);
     if (getVariable())
       getModel()->getMaxminSystem()->variable_free(getVariable());
     if (getModel()->getUpdateMechanism() == UM_LAZY) {
       /* remove from heap */
       heapRemove(getModel()->getActionHeap());
       if (action_lmm_hook.is_linked())
-        getModel()->getModifiedSet()->erase(getModel()->getModifiedSet()->iterator_to(*this));
+        simgrid::xbt::intrusive_erase(*getModel()->getModifiedSet(), *this);
     }
     delete this;
     return 1;