#include "src/surf/HostImpl.hpp"
#include "src/surf/cpu_interface.hpp"
-#include <boost/range/algorithm.hpp>
+#include <boost/core/demangle.hpp>
+#include <typeinfo>
#include <utility>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix, "Logging specific to SIMIX (process)");
{
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
}
* 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();
}
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")));
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()
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()
}
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_) {
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);
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()
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();
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) ||
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;
}
/** @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,