From: Arnaud Giersch Date: Mon, 4 Dec 2017 21:18:04 +0000 (+0100) Subject: Use simgrid::xbt::intrusive_erase(). X-Git-Tag: v3.18~161 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/863d7ae03c294566165effc8a6eff7fed7cb3e9f Use simgrid::xbt::intrusive_erase(). --- diff --git a/src/kernel/lmm/fair_bottleneck.cpp b/src/kernel/lmm/fair_bottleneck.cpp index 5ff0ef272f..71de3e7559 100644 --- a/src/kernel/lmm/fair_bottleneck.cpp +++ b/src/kernel/lmm/fair_bottleneck.cpp @@ -11,6 +11,7 @@ #include #include #include +#include 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 { diff --git a/src/kernel/lmm/maxmin.cpp b/src/kernel/lmm/maxmin.cpp index f9c28c978d..0c1fe8af97 100644 --- a/src/kernel/lmm/maxmin.cpp +++ b/src/kernel/lmm/maxmin.cpp @@ -10,6 +10,7 @@ #include "xbt/log.h" #include "xbt/mallocator.h" #include "xbt/sysdep.h" +#include "xbt/utility.hpp" #include #include #include @@ -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(); } diff --git a/src/kernel/lmm/maxmin.hpp b/src/kernel/lmm/maxmin.hpp index 3fc501f869..1d364228f0 100644 --- a/src/kernel/lmm/maxmin.hpp +++ b/src/kernel/lmm/maxmin.hpp @@ -12,6 +12,7 @@ #include "xbt/asserts.h" #include "xbt/mallocator.h" #include "xbt/misc.h" +#include "xbt/utility.hpp" #include #include #include @@ -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); diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 3effdcb81e..2295dd34d2 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -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()->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()->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()->process_list; - list.erase(list.iterator_to(*process)); + simgrid::xbt::intrusive_erase(process->host->extension()->process_list, *process); process->host = dest; dest->extension()->process_list.push_back(*process); } diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index bfa4e5362a..27ccc86c19 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -8,6 +8,7 @@ #include "cpu_ti.hpp" #include "simgrid/sg_config.h" #include "src/kernel/lmm/maxmin.hpp" +#include "xbt/utility.hpp" #include 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(model())->p_cpuRunningActionSetThatDoesNotNeedBeingChecked; action->getStateSet()->push_back(*action); } diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index d65cf3330c..d36dff6330 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -6,6 +6,7 @@ #include "cpu_ti.hpp" #include "src/surf/trace_mgr.hpp" +#include "xbt/utility.hpp" #include #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(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(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); diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 7c300951cf..85aab98915 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -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; diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index d94f6fbee4..0c026b4538 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -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; diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index 340c601333..130879dfa4 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -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 /*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()); diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index cb5ed0e386..f61c84fb41 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -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 #include @@ -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;