]> AND Public Git Repository - simgrid.git/blobdiff - src/kernel/actor/ActorImpl.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: Start implementing the dependency functions on the AppSide (TBC)
[simgrid.git] / src / kernel / actor / ActorImpl.cpp
index e2eb1842fb8c49a663817a6ebf8f541a45290542..06d324c4785cb77ca930750ad2f39b97be81656f 100644 (file)
@@ -19,7 +19,7 @@
 #include "src/surf/cpu_interface.hpp"
 
 #include <boost/core/demangle.hpp>
-#include <boost/range/algorithm.hpp>
+#include <typeinfo>
 #include <utility>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix, "Logging specific to SIMIX (process)");
@@ -45,15 +45,19 @@ unsigned long get_maxpid()
 {
   return maxpid;
 }
-ActorImpl* ActorImpl::by_PID(aid_t PID)
+unsigned long* get_maxpid_addr()
 {
-  auto item = simix_global->process_list.find(PID);
+  return &maxpid;
+}
+ActorImpl* ActorImpl::by_pid(aid_t pid)
+{
+  auto item = simix_global->process_list.find(pid);
   if (item != simix_global->process_list.end())
     return item->second;
 
   // Search the trash
   for (auto& a : simix_global->actors_to_destroy)
-    if (a.get_pid() == PID)
+    if (a.get_pid() == pid)
       return &a;
   return nullptr; // Not found, even in the trash
 }
@@ -86,8 +90,7 @@ ActorImpl::~ActorImpl()
  * In the future, it might be extended in order to attach other threads created by a third party library.
  */
 
-ActorImplPtr ActorImpl::attach(const std::string& name, void* data, s4u::Host* host,
-                               const std::unordered_map<std::string, std::string>* properties)
+ActorImplPtr ActorImpl::attach(const std::string& name, void* data, s4u::Host* host)
 {
   // This is mostly a copy/paste from create(), it'd be nice to share some code between those two functions.
 
@@ -107,12 +110,8 @@ ActorImplPtr ActorImpl::attach(const std::string& name, void* data, s4u::Host* h
   xbt_assert(simix_global != nullptr, "simix is not initialized, please call MSG_init first");
   actor->context_.reset(simix_global->context_factory->attach(actor));
 
-  /* Add properties */
-  if (properties != nullptr)
-    actor->set_properties(*properties);
-
   /* Add the actor to it's host actor list */
-  host->pimpl_->add_actor(actor);
+  host->get_impl()->add_actor(actor);
 
   /* Now insert it in the global actor list and in the actors to run list */
   simix_global->process_list[actor->get_pid()] = actor;
@@ -138,8 +137,7 @@ ActorImplPtr ActorImpl::attach(const std::string& name, void* data, s4u::Host* h
 void ActorImpl::detach()
 {
   auto* context = dynamic_cast<context::AttachContext*>(context::Context::self());
-  if (context == nullptr)
-    xbt_die("Not a suitable context");
+  xbt_assert(context != nullptr, "Not a suitable context");
 
   context->get_actor()->cleanup();
   context->attach_stop();
@@ -150,7 +148,7 @@ void ActorImpl::cleanup_from_simix()
   const std::lock_guard<std::mutex> lock(simix_global->mutex);
   simix_global->process_list.erase(pid_);
   if (host_ && host_actor_list_hook.is_linked())
-    host_->pimpl_->remove_actor(this);
+    host_->get_impl()->remove_actor(this);
   if (not smx_destroy_list_hook.is_linked()) {
 #if SIMGRID_HAVE_MC
     xbt_dynar_push_as(simix_global->dead_actors_vector, ActorImpl*, this);
@@ -224,10 +222,7 @@ void ActorImpl::exit()
     if (exec != nullptr) {
       exec->clean_action();
     } else if (comm != nullptr) {
-      // Remove first occurrence of &actor->simcall:
-      auto i = boost::range::find(waiting_synchro_->simcalls_, &simcall_);
-      if (i != waiting_synchro_->simcalls_.end())
-        waiting_synchro_->simcalls_.remove(&simcall_);
+      comm->unregister_simcall(&simcall_);
     } else {
       activity::ActivityImplPtr(waiting_synchro_)->finish();
     }
@@ -235,6 +230,9 @@ void ActorImpl::exit()
     activities_.remove(waiting_synchro_);
     waiting_synchro_ = nullptr;
   }
+  for (auto const& activity : activities_)
+    activity->cancel();
+  activities_.clear();
 
   // Forcefully kill the actor if its host is turned off. Not a HostFailureException because you should not survive that
   this->throw_exception(std::make_exception_ptr(ForcefulKillException(host_->is_on() ? "exited" : "host failed")));
@@ -285,7 +283,7 @@ void ActorImpl::set_kill_time(double kill_time)
 
 double ActorImpl::get_kill_time() const
 {
-  return kill_timer_ ? kill_timer_->get_date() : 0;
+  return kill_timer_ ? kill_timer_->date : 0.0;
 }
 
 void ActorImpl::yield()
@@ -306,12 +304,7 @@ void ActorImpl::yield()
 
   if (suspended_) {
     XBT_DEBUG("Hey! I'm suspended.");
-
     xbt_assert(exception_ == nullptr, "Gasp! This exception may be lost by subsequent calls.");
-
-    if (waiting_synchro_ != nullptr) // Not sure of when this will happen. Maybe when suspending early in the SR when a
-      waiting_synchro_->suspend();   // waiting_synchro was terminated
-
     yield(); // Yield back to maestro without proceeding with my execution. I'll get rescheduled by resume()
   }
 
@@ -361,13 +354,14 @@ s4u::Actor* ActorImpl::restart()
   XBT_DEBUG("Restarting actor %s on %s", get_cname(), host_->get_cname());
 
   // retrieve the arguments of the old actor
-  ProcessArg arg = ProcessArg(host_, this);
+  ProcessArg arg(host_, this);
 
   // kill the old actor
   context::Context::self()->get_actor()->kill(this);
 
   // start the new actor
-  ActorImplPtr actor = ActorImpl::create(arg.name, arg.code, arg.data, arg.host, arg.properties.get(), nullptr);
+  ActorImplPtr actor = ActorImpl::create(arg.name, arg.code, arg.data, arg.host, nullptr);
+  actor->set_properties(arg.properties);
   *actor->on_exit = std::move(*arg.on_exit);
   actor->set_kill_time(arg.kill_time);
   actor->set_auto_restart(arg.auto_restart);
@@ -384,10 +378,9 @@ void ActorImpl::suspend()
 
   suspended_ = true;
 
-  /* If the suspended actor is waiting on a sync, suspend its synchronization.
-   * Otherwise, it will suspend itself when scheduled, ie, very soon. */
-  if (waiting_synchro_ != nullptr)
-    waiting_synchro_->suspend();
+  /* Suspend the activities associated with this actor. */
+  for (auto const& activity : activities_)
+    activity->suspend();
 }
 
 void ActorImpl::resume()
@@ -403,10 +396,10 @@ void ActorImpl::resume()
     return;
   suspended_ = false;
 
-  /* resume the activity that was blocking the resumed actor. */
-  if (waiting_synchro_)
-    waiting_synchro_->resume();
-  else // Reschedule the actor if it was forcefully unscheduled in yield()
+  /* resume the activities that were blocked when suspending the actor. */
+  for (auto const& activity : activities_)
+    activity->resume();
+  if (not waiting_synchro_) // Reschedule the actor if it was forcefully unscheduled in yield()
     simix_global->actors_to_run.push_back(this);
 
   XBT_OUT();
@@ -451,8 +444,7 @@ void ActorImpl::throw_exception(std::exception_ptr e)
 void ActorImpl::simcall_answer()
 {
   if (this != simix_global->maestro_) {
-    XBT_DEBUG("Answer simcall %s (%d) issued by %s (%p)", SIMIX_simcall_name(simcall_.call_), (int)simcall_.call_,
-              get_cname(), this);
+    XBT_DEBUG("Answer simcall %s issued by %s (%p)", SIMIX_simcall_name(simcall_), get_cname(), this);
     xbt_assert(simcall_.call_ != simix::Simcall::NONE);
     simcall_.call_ = simix::Simcall::NONE;
     xbt_assert(not XBT_LOG_ISENABLED(simix_process, xbt_log_priority_debug) ||
@@ -465,9 +457,9 @@ void ActorImpl::simcall_answer()
 
 void ActorImpl::set_host(s4u::Host* dest)
 {
-  host_->pimpl_->remove_actor(this);
+  host_->get_impl()->remove_actor(this);
   host_ = dest;
-  dest->pimpl_->add_actor(this);
+  dest->get_impl()->add_actor(this);
 }
 
 ActorImplPtr ActorImpl::init(const std::string& name, s4u::Host* host) const
@@ -499,7 +491,7 @@ ActorImpl* ActorImpl::start(const ActorCode& code)
   XBT_DEBUG("Start context '%s'", get_cname());
 
   /* Add the actor to its host's actor list */
-  host_->pimpl_->add_actor(this);
+  host_->get_impl()->add_actor(this);
   simix_global->process_list[pid_] = this;
 
   /* Now insert it in the global actor list and in the actor to run list */
@@ -510,7 +502,6 @@ ActorImpl* ActorImpl::start(const ActorCode& code)
 }
 
 ActorImplPtr ActorImpl::create(const std::string& name, const ActorCode& code, void* data, s4u::Host* host,
-                               const std::unordered_map<std::string, std::string>* properties,
                                const ActorImpl* parent_actor)
 {
   XBT_DEBUG("Start actor %s@'%s'", name.c_str(), host->get_cname());
@@ -524,10 +515,6 @@ ActorImplPtr ActorImpl::create(const std::string& name, const ActorCode& code, v
   /* actor data */
   actor->set_user_data(data);
 
-  /* Add properties */
-  if (properties != nullptr)
-    actor->set_properties(*properties);
-
   actor->start(code);
 
   return actor;
@@ -580,9 +567,9 @@ const char* SIMIX_process_self_get_name()
 }
 
 /** @brief Returns the process from PID. */
-smx_actor_t SIMIX_process_from_PID(aid_t PID)
+smx_actor_t SIMIX_process_from_PID(aid_t pid)
 {
-  return simgrid::kernel::actor::ActorImpl::by_PID(PID);
+  return simgrid::kernel::actor::ActorImpl::by_pid(pid);
 }
 
 void SIMIX_process_on_exit(smx_actor_t actor,