-/* 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. */
#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)");
{
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()
{
* 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.
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;
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();
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);
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) {
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();
}
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()
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_) {
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);
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
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 */
}
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());
/* actor data */
actor->set_user_data(data);
- /* Add properties */
- if (properties != nullptr)
- actor->set_properties(*properties);
-
actor->start(code);
return actor;
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,