Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement simcall_HANDLER_execution_waitany_for into ExecImpl::wait_any_for.
[simgrid.git] / src / kernel / actor / ActorImpl.cpp
index e631755..0fcaa4b 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,6 +18,7 @@
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/cpu_interface.hpp"
 
+#include <boost/core/demangle.hpp>
 #include <boost/range/algorithm.hpp>
 #include <utility>
 
@@ -40,10 +41,26 @@ namespace kernel {
 namespace actor {
 
 static unsigned long maxpid = 0;
-int get_maxpid()
+unsigned long get_maxpid()
 {
   return maxpid;
 }
+void* 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()
 {
@@ -125,8 +142,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();
@@ -153,7 +169,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) {
@@ -306,7 +322,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,8 +370,7 @@ s4u::Actor* ActorImpl::restart()
   context::Context::self()->get_actor()->kill(this);
 
   // start the new actor
-  ActorImplPtr actor =
-      ActorImpl::create(arg.name, std::move(arg.code), arg.data, arg.host, arg.properties.get(), nullptr);
+  ActorImplPtr actor = ActorImpl::create(arg.name, arg.code, arg.data, arg.host, arg.properties.get(), nullptr);
   *actor->on_exit = std::move(*arg.on_exit);
   actor->set_kill_time(arg.kill_time);
   actor->set_auto_restart(arg.auto_restart);
@@ -437,8 +456,8 @@ 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_assert(simcall_.call_ != SIMCALL_NONE);
-    simcall_.call_ = SIMCALL_NONE;
+    xbt_assert(simcall_.call_ != simix::Simcall::NONE);
+    simcall_.call_ = simix::Simcall::NONE;
     xbt_assert(not XBT_LOG_ISENABLED(simix_process, xbt_log_priority_debug) ||
                    std::find(begin(simix_global->actors_to_run), end(simix_global->actors_to_run), this) ==
                        end(simix_global->actors_to_run),
@@ -563,25 +582,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,