X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/63225b9520042ef129adb975132fe68ec5710988..781aee7fedc47a3c0acc35a738b0ffdecdb15211:/src/s4u/s4u_Actor.cpp diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index 5b711b5f11..ac4af83d99 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -11,6 +11,7 @@ #include "simgrid/s4u/Host.hpp" #include "simgrid/s4u/VirtualMachine.hpp" #include "src/include/mc/mc.h" +#include "src/kernel/EngineImpl.hpp" #include "src/kernel/activity/ExecImpl.hpp" #include "src/mc/mc_replay.hpp" #include "src/surf/HostImpl.hpp" @@ -73,7 +74,8 @@ ActorPtr Actor::create(const std::string& name, s4u::Host* host, const std::func ActorPtr Actor::create(const std::string& name, s4u::Host* host, const std::string& function, std::vector args) { - const simix::ActorCodeFactory& factory = SIMIX_get_actor_code_factory(function); + const simgrid::kernel::actor::ActorCodeFactory& factory = + simgrid::kernel::EngineImpl::get_instance()->get_function(function); return create(name, host, factory(std::move(args))); } @@ -106,7 +108,7 @@ void Actor::join(double timeout) // The joined process is already finished, just wake up the issuer right away issuer->simcall_answer(); } else { - smx_activity_t sync = issuer->join(target, timeout); + kernel::activity::ActivityImplPtr sync = issuer->join(target, timeout); sync->register_simcall(&issuer->simcall); } }); @@ -315,7 +317,7 @@ void sleep_for(double duration) issuer->simcall_answer(); return; } - smx_activity_t sync = issuer->sleep(duration); + kernel::activity::ActivityImplPtr sync = issuer->sleep(duration); sync->register_simcall(&issuer->simcall); }); @@ -427,13 +429,6 @@ void suspend() kernel::actor::simcall_blocking([self] { self->suspend(); }); } -void resume() -{ - kernel::actor::ActorImpl* self = simgrid::kernel::actor::ActorImpl::self(); - kernel::actor::simcall([self] { self->resume(); }); - Actor::on_resume(*self->ciface()); -} - void exit() { kernel::actor::ActorImpl* self = simgrid::kernel::actor::ActorImpl::self(); @@ -469,19 +464,25 @@ 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) +void sg_actor_start(sg_actor_t actor, xbt_main_func_t code, int argc, const char* const* argv) { - simgrid::simix::ActorCode function; + simgrid::kernel::actor::ActorCode function; if (code) - function = simgrid::xbt::wrap_main(code, argc, static_cast(argv)); + function = simgrid::xbt::wrap_main(code, argc, argv); actor->start(std::move(function)); } +void sg_actor_exit() +{ + simgrid::s4u::this_actor::exit(); +} + /** @ingroup m_actor_management * @brief Returns the process ID of @a actor. * * This function checks whether @a actor is a valid pointer and return its PID (or 0 in case of problem). */ + aid_t sg_actor_get_PID(const_sg_actor_t actor) { /* Do not raise an exception here: this function is called by the logs @@ -758,3 +759,11 @@ void sg_actor_data_set(sg_actor_t actor, void* userdata) { actor->set_data(userdata); } +/** @brief Add a function to the list of "on_exit" functions for the current process. + * The on_exit functions are the functions executed when your process is killed. + * You should use them to free the data used by your process. + */ +void sg_actor_on_exit(int_f_int_pvoid_t fun, void* data) +{ + simgrid::s4u::this_actor::on_exit([fun, data](bool failed) { fun(failed ? 1 /*FAILURE*/ : 0 /*SUCCESS*/, data); }); +}