#include "src/surf/cpu_interface.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;
}
-void* get_maxpid_addr()
+unsigned long* get_maxpid_addr()
{
return &maxpid;
}
* 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;
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);
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")));
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("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;