From: Martin Quinson Date: Mon, 17 Aug 2015 14:25:14 +0000 (+0200) Subject: react sainly if the actor was not create by S4U but by the application deployment X-Git-Tag: v3_13~1690^2~9 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0983afc2177fdd196cd4a9d0945d842dc5351abd react sainly if the actor was not create by S4U but by the application deployment --- diff --git a/include/simgrid/s4u/actor.hpp b/include/simgrid/s4u/actor.hpp index 6b9c5245f0..bcfff139e3 100644 --- a/include/simgrid/s4u/actor.hpp +++ b/include/simgrid/s4u/actor.hpp @@ -41,13 +41,14 @@ class Mailbox; */ class Actor { friend Comm; + Actor(smx_process_t smx_proc); public: Actor(const char*name, s4u::Host *host, int argc, char **argv); Actor(const char*name, s4u::Host *host, int argc, char **argv, double killTime); virtual ~Actor() {} /** The main method of your agent */ - virtual int main(int argc, char **argv)=0; + int main(int argc, char **argv) {return 0;} /** The Actor that is currently running */ static Actor *current(); diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp index 64d429e25b..8a5dd1ca67 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_actor.cpp @@ -28,6 +28,9 @@ static int s4u_actor_runner(int argc, char **argv) { using namespace simgrid; +s4u::Actor::Actor(smx_process_t smx_proc) { + p_smx_process = smx_proc; +} s4u::Actor::Actor(const char *name, s4u::Host *host, int argc, char **argv) : s4u::Actor::Actor(name,host, argc,argv, -1) { } @@ -41,7 +44,10 @@ s4u::Actor::Actor(const char *name, s4u::Host *host, int argc, char **argv, doub s4u::Actor *s4u::Actor::current() { smx_process_t smx_proc = SIMIX_process_self(); - return (simgrid::s4u::Actor*) SIMIX_process_self_get_data(smx_proc); + simgrid::s4u::Actor* res = (simgrid::s4u::Actor*) SIMIX_process_self_get_data(smx_proc); + if (res == NULL) // The smx_process was not created by S4U (but by deployment?). Embed it in a S4U object + res = new Actor(smx_proc); + return res; } s4u::Actor *s4u::Actor::byPid(int pid) { return (simgrid::s4u::Actor*) SIMIX_process_self_get_data(SIMIX_process_from_PID(pid));