X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/fceda039b34654131e18f190e2c7e32db112ef21..4e7df12e1e81b2ff9212175628873d6d880b6630:/src/s4u/s4u_Actor.cpp diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index 64ce673799..80cd55af9b 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -13,7 +13,6 @@ #include "src/include/mc/mc.h" #include "src/kernel/activity/ExecImpl.hpp" #include "src/mc/mc_replay.hpp" -#include "src/simix/smx_private.hpp" #include "src/surf/HostImpl.hpp" #include @@ -43,9 +42,10 @@ Actor* Actor::self() return self_context->get_actor()->ciface(); } + ActorPtr Actor::init(const std::string& name, s4u::Host* host) { - smx_actor_t self = SIMIX_process_self(); + kernel::actor::ActorImpl* self = SIMIX_process_self(); kernel::actor::ActorImpl* actor = kernel::actor::simcall([self, &name, host] { return self->init(name, host).get(); }); return actor->iface(); @@ -59,7 +59,7 @@ ActorPtr Actor::start(const std::function& code) ActorPtr Actor::create(const std::string& name, s4u::Host* host, const std::function& code) { - smx_actor_t self = SIMIX_process_self(); + kernel::actor::ActorImpl* self = SIMIX_process_self(); kernel::actor::ActorImpl* actor = kernel::actor::simcall([self, &name, host, &code] { return self->init(name, host)->start(code); }); @@ -95,8 +95,8 @@ void Actor::join() void Actor::join(double timeout) { - auto issuer = SIMIX_process_self(); - auto target = pimpl_; + kernel::actor::ActorImpl* issuer = SIMIX_process_self(); + kernel::actor::ActorImpl* target = pimpl_; kernel::actor::simcall_blocking([issuer, target, timeout] { if (target->finished_) { // The joined process is already finished, just wake up the issuer right away @@ -115,16 +115,11 @@ void Actor::set_auto_restart(bool autorestart) pimpl_->set_auto_restart(autorestart); kernel::actor::ProcessArg* arg = new kernel::actor::ProcessArg(pimpl_->get_host(), pimpl_); - XBT_DEBUG("Adding Process %s to the actors_at_boot_ list of Host %s", arg->name.c_str(), arg->host->get_cname()); - pimpl_->get_host()->pimpl_->actors_at_boot_.emplace_back(arg); + XBT_DEBUG("Adding %s to the actors_at_boot_ list of Host %s", arg->name.c_str(), arg->host->get_cname()); + pimpl_->get_host()->pimpl_->add_actor_at_boot(arg); }); } -void Actor::on_exit(const std::function& fun, void* data) /* deprecated */ -{ - on_exit([fun, data](bool failed) { fun(failed ? SMX_EXIT_FAILURE : SMX_EXIT_SUCCESS, data); }); -} - void Actor::on_exit(const std::function& fun) const { kernel::actor::simcall([this, &fun] { SIMIX_process_on_exit(pimpl_, fun); }); @@ -186,8 +181,8 @@ aid_t Actor::get_ppid() const void Actor::suspend() { - auto issuer = SIMIX_process_self(); - auto target = pimpl_; + kernel::actor::ActorImpl* issuer = SIMIX_process_self(); + kernel::actor::ActorImpl* target = pimpl_; s4u::Actor::on_suspend(*this); kernel::actor::simcall_blocking([issuer, target]() { target->suspend(); @@ -220,35 +215,19 @@ double Actor::get_kill_time() return pimpl_->get_kill_time(); } -void Actor::kill(aid_t pid) // deprecated -{ - kernel::actor::ActorImpl* killer = SIMIX_process_self(); - kernel::actor::ActorImpl* victim = SIMIX_process_from_PID(pid); - if (victim != nullptr) { - kernel::actor::simcall([killer, victim] { killer->kill(victim); }); - } else { - std::ostringstream oss; - oss << "kill: (" << pid << ") - No such actor" << std::endl; - throw std::runtime_error(oss.str()); - } -} - void Actor::kill() { - kernel::actor::ActorImpl* process = SIMIX_process_self(); - kernel::actor::simcall([this, process] { - xbt_assert(pimpl_ != simix_global->maestro_process, "Killing maestro is a rather bad idea"); - process->kill(pimpl_); - }); + kernel::actor::ActorImpl* self = SIMIX_process_self(); + kernel::actor::simcall([this, self] { self->kill(pimpl_); }); } // ***** Static functions ***** ActorPtr Actor::by_pid(aid_t pid) { - kernel::actor::ActorImpl* process = SIMIX_process_from_PID(pid); - if (process != nullptr) - return process->iface(); + kernel::actor::ActorImpl* actor = SIMIX_process_from_PID(pid); + if (actor != nullptr) + return actor->iface(); else return ActorPtr(); } @@ -295,8 +274,7 @@ namespace this_actor { */ bool is_maestro() { - kernel::actor::ActorImpl* process = SIMIX_process_self(); - return process == nullptr || process == simix_global->maestro_process; + return SIMIX_is_maestro(); } void sleep_for(double duration) @@ -375,27 +353,6 @@ void parallel_execute(const std::vector& hosts, const std::vectorset_timeout(timeout)->wait(); } -// deprecated -void parallel_execute(int host_nb, s4u::Host* const* host_list, const double* flops_amount, const double* bytes_amount, - double timeout) -{ - smx_activity_t s = - simcall_execution_parallel_start("", host_nb, host_list, flops_amount, bytes_amount, /* rate */ -1, timeout); - simcall_execution_wait(s); - delete[] flops_amount; - delete[] bytes_amount; -} - -// deprecated -void parallel_execute(int host_nb, s4u::Host* const* host_list, const double* flops_amount, const double* bytes_amount) -{ - smx_activity_t s = simcall_execution_parallel_start("", host_nb, host_list, flops_amount, bytes_amount, - /* rate */ -1, /*timeout*/ -1); - simcall_execution_wait(s); - delete[] flops_amount; - delete[] bytes_amount; -} - ExecPtr exec_init(double flops_amount) { return ExecPtr(new ExecSeq(get_host(), flops_amount)); @@ -464,11 +421,6 @@ void on_exit(const std::function& fun) SIMIX_process_self()->iface()->on_exit(fun); } -void on_exit(const std::function& fun, void* data) /* deprecated */ -{ - SIMIX_process_self()->iface()->on_exit([fun, data](bool exit) { fun(exit, data); }); -} - /** @brief Moves the current actor to another host * * @see simgrid::s4u::Actor::migrate() for more information @@ -484,6 +436,19 @@ void migrate(Host* new_host) /* **************************** Public C interface *************************** */ +sg_actor_t sg_actor_init(const char* name, sg_host_t host) +{ + return simgrid::s4u::Actor::init(name, host).get(); +} + +void sg_actor_start(sg_actor_t actor, xbt_main_func_t code, int argc, char** argv) +{ + simgrid::simix::ActorCode function; + if (code) + function = simgrid::xbt::wrap_main(code, argc, static_cast(argv)); + actor->start(std::move(function)); +} + /** @ingroup m_actor_management * @brief Returns the process ID of @a actor. * @@ -560,7 +525,7 @@ xbt_dict_t sg_actor_get_properties(sg_actor_t actor) if (props == nullptr) return nullptr; for (auto const& kv : *props) { - xbt_dict_set(as_dict, kv.first.c_str(), xbt_strdup(kv.second.c_str()), nullptr); + xbt_dict_set(as_dict, kv.first.c_str(), xbt_strdup(kv.second.c_str())); } return as_dict; } @@ -742,12 +707,12 @@ void sg_actor_unref(sg_actor_t actor) } /** @brief Return the user data of a #sg_actor_t */ -void* sg_actor_get_data(sg_actor_t actor) +void* sg_actor_data(sg_actor_t actor) { return actor->get_data(); } /** @brief Set the user data of a #sg_actor_t */ -void sg_actor_set_data(sg_actor_t actor, void* userdata) +void sg_actor_data_set(sg_actor_t actor, void* userdata) { actor->set_data(userdata); }