From 1485fe26372c540b07a9a86a5d08155d06d77e81 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 1 Jul 2018 19:15:57 +0200 Subject: [PATCH] simplify SIMIX_host_add_auto_restart_process --- src/simix/ActorImpl.cpp | 4 +-- src/simix/ActorImpl.hpp | 58 ++++++++++++++++++++-------------- src/simix/smx_host.cpp | 8 ++--- src/simix/smx_host_private.hpp | 6 +--- 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 55cd83357b..38b423db28 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -709,9 +709,7 @@ void SIMIX_process_yield(smx_actor_t self) SIMIX_process_on_exit_runall(self); /* Add the process to the list of process to restart, only if the host is down */ if (self->auto_restart_ && self->host_->is_off()) { - SIMIX_host_add_auto_restart_process(self->host_, self->get_cname(), self->code, self->get_user_data(), - SIMIX_timer_get_date(self->kill_timer), self->get_properties(), - self->auto_restart_); + SIMIX_host_add_auto_restart_process(self->host_, self); } XBT_DEBUG("Process %s@%s is dead", self->get_cname(), self->host_->get_cname()); self->context_->stop(); diff --git a/src/simix/ActorImpl.hpp b/src/simix/ActorImpl.hpp index 5d610f7972..1a3c47bd0c 100644 --- a/src/simix/ActorImpl.hpp +++ b/src/simix/ActorImpl.hpp @@ -23,29 +23,6 @@ namespace simgrid { namespace kernel { namespace actor { -class ProcessArg { -public: - std::string name; - std::function code; - void* data = nullptr; - s4u::Host* host = nullptr; - double kill_time = 0.0; - std::shared_ptr> properties; - bool auto_restart = false; - ProcessArg() = default; - explicit ProcessArg(std::string name, std::function code, void* data, s4u::Host* host, double kill_time, - std::shared_ptr> properties, bool auto_restart) - : name(name) - , code(std::move(code)) - , data(data) - , host(host) - , kill_time(kill_time) - , properties(properties) - , auto_restart(auto_restart) - { - } -}; - class ActorImpl : public simgrid::surf::PropertyHolder { public: ActorImpl() : piface_(this) {} @@ -126,6 +103,41 @@ public: void* get_user_data() { return userdata_; } }; +class ProcessArg { +public: + std::string name; + std::function code; + void* data = nullptr; + s4u::Host* host = nullptr; + double kill_time = 0.0; + std::shared_ptr> properties = nullptr; + bool auto_restart = false; + ProcessArg() = default; + + explicit ProcessArg(std::string name, std::function code, void* data, s4u::Host* host, double kill_time, + std::shared_ptr> properties, bool auto_restart) + : name(name) + , code(std::move(code)) + , data(data) + , host(host) + , kill_time(kill_time) + , properties(properties) + , auto_restart(auto_restart) + { + } + + explicit ProcessArg(s4u::Host* host, ActorImpl* actor) + : name(actor->get_name()) + , code(std::move(actor->code)) + , data(actor->get_user_data()) + , host(host) + , kill_time(SIMIX_timer_get_date(actor->kill_timer)) + , auto_restart(actor->auto_restart_) + { + properties.reset(actor->get_properties(), [](decltype(actor->get_properties())) {}); + } +}; + /* Used to keep the list of actors blocked on a synchro */ typedef boost::intrusive::list, &ActorImpl::smx_synchro_hook>> diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index afd0d0c928..3e565cbc86 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -78,13 +78,9 @@ const char* sg_host_self_get_name() * The processes will only be restarted once, meaning that you will have to register the process * again to restart the process again. */ -void SIMIX_host_add_auto_restart_process(sg_host_t host, const char* name, simgrid::simix::ActorCode code, void* data, - double kill_time, std::unordered_map* properties, - int auto_restart) +void SIMIX_host_add_auto_restart_process(sg_host_t host, simgrid::kernel::actor::ActorImpl* actor) { - simgrid::kernel::actor::ProcessArg* arg = - new simgrid::kernel::actor::ProcessArg(name, code, data, host, kill_time, nullptr, auto_restart); - arg->properties.reset(properties, [](decltype(properties)) {}); + simgrid::kernel::actor::ProcessArg* arg = new simgrid::kernel::actor::ProcessArg(host, actor); if (host->is_off() && watched_hosts.find(host->get_cname()) == watched_hosts.end()) { watched_hosts.insert(host->get_cname()); diff --git a/src/simix/smx_host_private.hpp b/src/simix/smx_host_private.hpp index 1fd17966db..87d081addb 100644 --- a/src/simix/smx_host_private.hpp +++ b/src/simix/smx_host_private.hpp @@ -38,11 +38,7 @@ public: } } -XBT_PRIVATE void SIMIX_host_add_auto_restart_process(sg_host_t host, const char* name, std::function code, - void* data, double kill_time, - std::unordered_map* properties, - int auto_restart); - +XBT_PRIVATE void SIMIX_host_add_auto_restart_process(sg_host_t host, simgrid::kernel::actor::ActorImpl* actor); XBT_PRIVATE void SIMIX_host_autorestart(sg_host_t host); XBT_PRIVATE void SIMIX_execution_finish(smx_activity_t synchro); -- 2.20.1