Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[s4u] Move actions by the current actor in the this_actor namespace
authorGabriel Corona <gabriel.corona@loria.fr>
Mon, 23 May 2016 08:55:08 +0000 (10:55 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Mon, 23 May 2016 08:55:28 +0000 (10:55 +0200)
This mimics the design of std::thread and std::this_thread.

We might want to create a convenience base class for actor
implementations with those functions as instance methods.

examples/s4u/basic/s4u_basic.cpp
include/simgrid/s4u/actor.hpp
src/s4u/s4u_actor.cpp

index 3da68af..11b3e11 100644 (file)
@@ -13,7 +13,7 @@ class Worker {
 public:
   void operator()() {
     XBT_INFO("Hello s4u, I'm ready to serve");
-    char *msg = (char*)simgrid::s4u::Actor::recv(*simgrid::s4u::Mailbox::byName("worker"));
+    char *msg = (char*)simgrid::s4u::this_actor::recv(*simgrid::s4u::Mailbox::byName("worker"));
     XBT_INFO("I received '%s'",msg);
     XBT_INFO("I'm done. See you.");
   }
@@ -24,7 +24,7 @@ public:
   void operator()() {
     const char *msg = "GaBuZoMeu";
     XBT_INFO("Hello s4u, I have something to send");
-    simgrid::s4u::Actor::send(*simgrid::s4u::Mailbox::byName("worker"), xbt_strdup(msg), strlen(msg));
+    simgrid::s4u::this_actor::send(*simgrid::s4u::Mailbox::byName("worker"), xbt_strdup(msg), strlen(msg));
     XBT_INFO("I'm done. See you.");
   }
 };
index 9b461eb..b671425 100644 (file)
@@ -79,30 +79,34 @@ public:
   /** Ask kindly to all actors to die. Only the issuer will survive. */
   static void killAll();
 
+protected:
+  smx_process_t getInferior() {return pimpl_;}
+private:
+  smx_process_t pimpl_ = nullptr;
+};
+
+namespace this_actor {
+
   // Static methods working on the current actor:
 
   /** Block the actor sleeping for that amount of seconds (may throws hostFailure) */
-  static void sleep(double duration);
+  void sleep(double duration);
 
   /** Block the actor, computing the given amount of flops */
-  static e_smx_state_t execute(double flop);
+  e_smx_state_t execute(double flop);
 
   /** Block the actor until it gets a message from the given mailbox.
    *
    * See \ref Comm for the full communication API (including non blocking communications).
    */
-  static void *recv(Mailbox &chan);
+  void *recv(Mailbox &chan);
 
   /** Block the actor until it delivers a message of the given simulated size to the given mailbox
    *
    * See \ref Comm for the full communication API (including non blocking communications).
   */
-  static void send(Mailbox &chan, void*payload, size_t simulatedSize);
+  void send(Mailbox &chan, void*payload, size_t simulatedSize);
 
-protected:
-  smx_process_t getInferior() {return pimpl_;}
-private:
-  smx_process_t pimpl_ = nullptr;
 };
 
 }} // namespace simgrid::s4u
index 0e82cee..a220c8c 100644 (file)
@@ -63,16 +63,21 @@ void s4u::Actor::killAll() {
   simcall_process_killall(1);
 }
 
-void s4u::Actor::sleep(double duration) {
+
+namespace simgrid {
+namespace s4u {
+namespace this_actor {
+
+void sleep(double duration) {
   simcall_process_sleep(duration);
 }
 
-e_smx_state_t s4u::Actor::execute(double flops) {
+e_smx_state_t execute(double flops) {
   smx_synchro_t s = simcall_execution_start(NULL,flops,1.0/*priority*/,0./*bound*/, 0L/*affinity*/);
   return simcall_execution_wait(s);
 }
 
-void *s4u::Actor::recv(Mailbox &chan) {
+voidrecv(Mailbox &chan) {
   void *res = NULL;
   Comm c = Comm::recv_init(chan);
   c.setDstData(&res,sizeof(res));
@@ -80,10 +85,14 @@ void *s4u::Actor::recv(Mailbox &chan) {
   return res;
 }
 
-void s4u::Actor::send(Mailbox &chan, void *payload, size_t simulatedSize) {
+void send(Mailbox &chan, void *payload, size_t simulatedSize) {
   Comm c = Comm::send_init(chan);
   c.setRemains(simulatedSize);
   c.setSrcData(payload);
   // c.start() is optional.
   c.wait();
 }
+
+}
+}
+}