Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Inline function.
[simgrid.git] / src / kernel / actor / ActorImpl.cpp
index 050908b2b8abfaf2e0182cd62929899adaf510be..6bd069817bd34312856d1553a5759714deb81e07 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -18,7 +18,7 @@
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/cpu_interface.hpp"
 
-#include <boost/range/algorithm.hpp>
+#include <boost/core/demangle.hpp>
 #include <utility>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix, "Logging specific to SIMIX (process)");
@@ -44,6 +44,22 @@ unsigned long get_maxpid()
 {
   return maxpid;
 }
+unsigned long* get_maxpid_addr()
+{
+  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)
+      return &a;
+  return nullptr; // Not found, even in the trash
+}
 
 ActorImpl* ActorImpl::self()
 {
@@ -73,8 +89,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.
 
@@ -94,12 +109,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;
@@ -125,8 +136,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();
@@ -137,7 +147,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);
@@ -153,7 +163,7 @@ void ActorImpl::cleanup()
   if (has_to_auto_restart() && not get_host()->is_on()) {
     XBT_DEBUG("Insert host %s to watched_hosts because it's off and %s needs to restart", get_host()->get_cname(),
               get_cname());
-    watched_hosts.insert(get_host()->get_name());
+    watched_hosts().insert(get_host()->get_name());
   }
 
   if (on_exit) {
@@ -211,10 +221,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();
     }
@@ -272,7 +279,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,7 +313,11 @@ void ActorImpl::yield()
     XBT_DEBUG("Wait, maestro left me an exception");
     std::exception_ptr exception = std::move(exception_);
     exception_                   = nullptr;
-    std::rethrow_exception(std::move(exception));
+    try {
+      std::rethrow_exception(std::move(exception));
+    } catch (const simgrid::Exception& e) {
+      e.rethrow_nested(XBT_THROW_POINT, boost::core::demangle(typeid(e).name()) + " raised in kernel mode.");
+    }
   }
 
   if (SMPI_switch_data_segment && not finished_) {
@@ -350,7 +361,8 @@ s4u::Actor* ActorImpl::restart()
   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);
@@ -448,9 +460,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
@@ -482,7 +494,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 */
@@ -493,7 +505,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());
@@ -507,10 +518,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;
@@ -562,25 +569,10 @@ const char* SIMIX_process_self_get_name()
   return SIMIX_is_maestro() ? "maestro" : simgrid::kernel::actor::ActorImpl::self()->get_cname();
 }
 
-/**
- * @brief Calling this function makes the process to yield.
- *
- * Only the current process can call this function, giving back the control to maestro.
- *
- * @param self the current process
- */
-
 /** @brief Returns the process from PID. */
-smx_actor_t SIMIX_process_from_PID(aid_t PID)
-{
-  auto item = simix_global->process_list.find(PID);
-  if (item == simix_global->process_list.end()) {
-    for (auto& a : simix_global->actors_to_destroy)
-      if (a.get_pid() == PID)
-        return &a;
-    return nullptr; // Not found, even in the trash
-  }
-  return item->second;
+smx_actor_t SIMIX_process_from_PID(aid_t pid)
+{
+  return simgrid::kernel::actor::ActorImpl::by_pid(pid);
 }
 
 void SIMIX_process_on_exit(smx_actor_t actor,