Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Shutdown Engine first, and fix double-free errors.
[simgrid.git] / src / surf / surf_interface.cpp
index cb5ed0e..02dfd42 100644 (file)
@@ -8,8 +8,10 @@
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/sg_config.h"
 #include "src/instr/instr_private.hpp" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
+#include "src/kernel/lmm/maxmin.hpp"   // Constraint
 #include "src/kernel/routing/NetPoint.hpp"
 #include "src/surf/HostImpl.hpp"
+#include "xbt/utility.hpp"
 
 #include <fstream>
 #include <set>
@@ -319,7 +321,7 @@ void surf_exit()
 {
   TRACE_end();                  /* Just in case it was not called by the upper layer (or there is no upper layer) */
 
-  sg_host_exit();
+  simgrid::s4u::Engine::shutdown();
   sg_link_exit();
   for (auto const& e : storage_types) {
     simgrid::surf::StorageType* stype = e.second;
@@ -344,7 +346,6 @@ void surf_exit()
 
   tmgr_finalize();
   sg_platf_exit();
-  simgrid::s4u::Engine::shutdown();
 
   NOW = 0;                      /* Just in case the user plans to restart the simulation afterward */
 }
@@ -374,6 +375,8 @@ Model::~Model(){
   delete runningActionSet_;
   delete failedActionSet_;
   delete doneActionSet_;
+  delete modifiedSet_;
+  delete maxminSystem_;
 }
 
 Action* Model::actionHeapPop()
@@ -539,6 +542,11 @@ void Resource::turnOff()
   isOn_ = false;
 }
 
+double Resource::getLoad()
+{
+  return constraint_->get_usage();
+}
+
 Model* Resource::model() const
 {
   return model_;
@@ -622,7 +630,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 +699,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 +708,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;