*/
smx_actor_t SIMIX_process_self()
{
- smx_context_t self_context = simgrid::kernel::context::Context::self();
+ simgrid::kernel::context::Context* self_context = simgrid::kernel::context::Context::self();
return (self_context != nullptr) ? self_context->get_actor() : nullptr;
}
void ActorImpl::cleanup()
{
+ finished_ = true;
+
+ 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());
+ }
+
+ // Execute the termination callbacks
+ smx_process_exit_status_t exit_status = (context_->iwannadie) ? SMX_EXIT_FAILURE : SMX_EXIT_SUCCESS;
+ while (not on_exit.empty()) {
+ s_smx_process_exit_fun_t exit_fun = on_exit.back();
+ on_exit.pop_back();
+ (exit_fun.fun)(exit_status, exit_fun.arg);
+ }
+
+ /* cancel non-blocking activities */
+ for (auto activity : comms)
+ boost::static_pointer_cast<activity::CommImpl>(activity)->cancel();
+ comms.clear();
+
+ XBT_DEBUG("%s@%s(%ld) should not run anymore", get_cname(), get_host()->get_cname(), get_pid());
+
if (this == simix_global->maestro_process) /* Do not cleanup maestro */
return;
#endif
simix_global->actors_to_destroy.push_back(*this);
}
- context_->iwannadie = false;
simix_global->mutex.unlock();
+
+ context_->iwannadie = false; // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops
+ simgrid::simix::simcall([this] { simgrid::s4u::Actor::on_destruction(iface()); });
+ context_->iwannadie = true;
}
void ActorImpl::exit()
XBT_DEBUG("Control returned to me: '%s'", get_cname());
if (context_->iwannadie) {
-
XBT_DEBUG("Actor %s@%s is dead", get_cname(), host_->get_cname());
// throw simgrid::kernel::context::ForcefulKillException(); Does not seem to properly kill the actor
context_->stop();
s4u::Actor* ActorImpl::restart()
{
+ xbt_assert(this != simix_global->maestro_process, "Restarting maestro is not supported");
+
XBT_DEBUG("Restarting actor %s on %s", get_cname(), host_->get_cname());
// retrieve the arguments of the old actor
ProcessArg arg = ProcessArg(host_, this);
// kill the old actor
- (this == simix_global->maestro_process) ? this->exit() : SIMIX_process_self()->kill(this);
+ context::Context::self()->get_actor()->kill(this);
// start the new actor
ActorImplPtr actor =