X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/cdc03fc96da89f61950be092cf6b7ac069075e29..4e7df12e1e81b2ff9212175628873d6d880b6630:/src/s4u/s4u_Actor.cpp diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index 51bfd453cd..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 @@ -181,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(); @@ -217,20 +217,17 @@ double Actor::get_kill_time() 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(); } @@ -277,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) @@ -440,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. * @@ -516,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; }