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.
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.");
}
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.");
}
};
/** 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
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) {
+void* recv(Mailbox &chan) {
void *res = NULL;
Comm c = Comm::recv_init(chan);
c.setDstData(&res,sizeof(res));
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();
}
+
+}
+}
+}