Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Replaced std::list by std::set to keep track of activities
authorHenri Casanova <henric@hawaii.edu>
Thu, 1 Dec 2022 17:33:13 +0000 (07:33 -1000)
committerHenri Casanova <henric@hawaii.edu>
Thu, 1 Dec 2022 17:33:13 +0000 (07:33 -1000)
src/kernel/activity/CommImpl.cpp
src/kernel/activity/ExecImpl.cpp
src/kernel/activity/IoImpl.cpp
src/kernel/actor/ActorImpl.cpp
src/kernel/actor/ActorImpl.hpp

index 70f560e..f84a555 100644 (file)
@@ -88,7 +88,7 @@ CommImpl& CommImpl::set_dst_buff(unsigned char* buff, size_t* size)
 CommImpl& CommImpl::detach()
 {
   detached_ = true;
-  EngineImpl::get_instance()->get_maestro()->activities_.emplace_back(this);
+  EngineImpl::get_instance()->get_maestro()->activities_.insert(this);
   return *this;
 }
 
@@ -245,7 +245,7 @@ ActivityImplPtr CommImpl::isend(actor::CommIsendSimcall* observer)
     other_comm->clean_fun = observer->get_clean_fun();
   } else {
     other_comm->clean_fun = nullptr;
-    observer->get_issuer()->activities_.emplace_back(other_comm);
+    observer->get_issuer()->activities_.insert(other_comm);
   }
 
   /* Setup the communication synchro */
@@ -294,7 +294,7 @@ ActivityImplPtr CommImpl::irecv(actor::CommIrecvSimcall* observer)
         other_comm = std::move(this_synchro);
         mbox->push(other_comm);
       }
-      observer->get_issuer()->activities_.emplace_back(other_comm);
+      observer->get_issuer()->activities_.insert(other_comm);
     }
   } else {
     /* Prepare a comm describing us, so that it gets passed to the user-provided filter of other side */
@@ -315,7 +315,7 @@ ActivityImplPtr CommImpl::irecv(actor::CommIrecvSimcall* observer)
 
       other_comm->set_state(simgrid::kernel::activity::State::READY);
     }
-    observer->get_issuer()->activities_.emplace_back(other_comm);
+    observer->get_issuer()->activities_.insert(other_comm);
   }
   observer->set_comm(other_comm.get());
 
@@ -519,7 +519,7 @@ void CommImpl::finish()
     copy_data();
 
   if (detached_)
-    EngineImpl::get_instance()->get_maestro()->activities_.remove(this);
+    EngineImpl::get_instance()->get_maestro()->activities_.erase(this);
 
   while (not simcalls_.empty()) {
     actor::Simcall* simcall = simcalls_.front();
@@ -547,12 +547,12 @@ void CommImpl::finish()
     }
 
     simcall->issuer_->waiting_synchro_ = nullptr;
-    simcall->issuer_->activities_.remove(this);
+    simcall->issuer_->activities_.erase(this);
     if (detached_) {
       if (simcall->issuer_ != dst_actor_ && dst_actor_ != nullptr)
-        dst_actor_->activities_.remove(this);
+        dst_actor_->activities_.erase(this);
       if (simcall->issuer_ != src_actor_ && src_actor_ != nullptr)
-        src_actor_->activities_.remove(this);
+        src_actor_->activities_.erase(this);
     }
   }
 }
index 32bbd8a..dc83190 100644 (file)
@@ -25,7 +25,7 @@ ExecImpl::ExecImpl()
   actor::ActorImpl* self = actor::ActorImpl::self();
   if (self) {
     set_actor(self);
-    self->activities_.emplace_back(this);
+    self->activities_.insert(this);
   }
 }
 
@@ -167,7 +167,7 @@ void ExecImpl::post()
   clean_action();
   timeout_detector_.reset();
   if (get_actor() != nullptr) {
-    get_actor()->activities_.remove(this);
+    get_actor()->activities_.erase(this);
   }
   if (get_state() != State::FAILED && cb_id_ >= 0)
     s4u::Host::on_state_change.disconnect(cb_id_);
index e3b2c98..503f2e6 100644 (file)
@@ -27,7 +27,7 @@ IoImpl::IoImpl()
   actor::ActorImpl* self = actor::ActorImpl::self();
   if (self) {
     set_actor(self);
-    self->activities_.emplace_back(this);
+    self->activities_.insert(this);
   }
 }
 
index b1cb37b..dea0e72 100644 (file)
@@ -190,7 +190,7 @@ void ActorImpl::exit()
     activity->set_state(activity::State::FAILED);
     activity->post();
 
-    activities_.remove(waiting_synchro_);
+    activities_.erase(waiting_synchro_);
     waiting_synchro_ = nullptr;
   }
   for (auto const& activity : activities_)
@@ -389,7 +389,7 @@ void ActorImpl::throw_exception(std::exception_ptr e)
   /* cancel the blocking synchro if any */
   if (waiting_synchro_) {
     waiting_synchro_->cancel();
-    activities_.remove(waiting_synchro_);
+    activities_.erase(waiting_synchro_);
     waiting_synchro_ = nullptr;
   }
 }
index 8efbc18..9e2d363 100644 (file)
@@ -17,6 +17,8 @@
 #include <functional>
 #include <list>
 #include <map>
+#include <set>
+#include <unordered_set>
 #include <memory>
 
 namespace simgrid::kernel::actor {
@@ -105,7 +107,7 @@ public:
   bool suspended_ = false;
 
   activity::ActivityImplPtr waiting_synchro_ = nullptr; /* the current blocking synchro if any */
-  std::list<activity::ActivityImplPtr> activities_;     /* the current non-blocking synchros */
+  std::set<activity::ActivityImplPtr> activities_;     /* the current non-blocking synchros */
   Simcall simcall_;
   /* list of functions executed when the actor dies */
   std::shared_ptr<std::vector<std::function<void(bool)>>> on_exit =