Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
react sainly if the actor was not create by S4U but by the application deployment
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 17 Aug 2015 14:25:14 +0000 (16:25 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 17 Aug 2015 14:25:14 +0000 (16:25 +0200)
include/simgrid/s4u/actor.hpp
src/s4u/s4u_actor.cpp

index 6b9c524..bcfff13 100644 (file)
@@ -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();
index 64d429e..8a5dd1c 100644 (file)
@@ -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));