Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rework the OO design of S4U comms
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 6 Jul 2017 00:46:16 +0000 (02:46 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 6 Jul 2017 00:46:21 +0000 (02:46 +0200)
This sounds much better this way:
-  simgrid::s4u::this_actor::send(mailbox, &pid, comm_size);
+  mailbox->send(&pid, comm_size);

That's intrusive for our (early) users, but the old way should still
work. Only, it raises a deprecation warning.

17 files changed:
examples/s4u/actions-comm/s4u_actions-comm.cpp
examples/s4u/actor-create/s4u_actor-create.cpp
examples/s4u/app-masterworker/s4u_app-masterworker.cpp
examples/s4u/app-token-ring/s4u_app-token-ring.cpp
examples/s4u/dht-chord/node.cpp
examples/s4u/dht-chord/s4u_dht-chord.hpp
include/simgrid/s4u/Actor.hpp
include/simgrid/s4u/Comm.hpp
include/simgrid/s4u/Mailbox.hpp
src/s4u/s4u_actor.cpp
src/s4u/s4u_comm.cpp
src/s4u/s4u_mailbox.cpp
teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp
teshsuite/s4u/comm-waitany/comm-waitany.cpp
teshsuite/s4u/listen_async/listen_async.cpp
teshsuite/s4u/pid/pid.cpp
teshsuite/s4u/storage_client_server/storage_client_server.cpp

index 523f3a4..a478625 100644 (file)
@@ -64,7 +64,7 @@ public:
     simgrid::s4u::MailboxPtr to = simgrid::s4u::Mailbox::byName(simgrid::s4u::this_actor::name() + "_" + action[2]);
     ACT_DEBUG("Entering Send: %s (size: %g) -- Actor %s on mailbox %s", NAME, size,
               simgrid::s4u::this_actor::name().c_str(), to->name());
-    simgrid::s4u::this_actor::send(to, payload, size);
+    to->send(payload, size);
     xbt_free(payload);
 
     log_action(action, simgrid::s4u::Engine::getClock() - clock);
index 56c2849..857b60a 100644 (file)
@@ -42,7 +42,7 @@ public:
     XBT_INFO("Hello s4u, I have something to send");
     simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName("mb42");
 
-    simgrid::s4u::this_actor::send(mailbox, xbt_strdup(msg.c_str()), msg.size());
+    mailbox->send(xbt_strdup(msg.c_str()), msg.size());
     XBT_INFO("I'm done. See you.");
   }
 };
@@ -74,8 +74,8 @@ public:
   {
     XBT_INFO("Hello s4u, I'm ready to get any message you'd want on %s", mailbox->name());
 
-    char* msg1 = static_cast<char*>(simgrid::s4u::this_actor::recv(mailbox));
-    char* msg2 = static_cast<char*>(simgrid::s4u::this_actor::recv(mailbox));
+    char* msg1 = static_cast<char*>(mailbox->recv());
+    char* msg2 = static_cast<char*>(mailbox->recv());
     XBT_INFO("I received '%s' and '%s'", msg1, msg2);
     xbt_free(msg1);
     xbt_free(msg2);
index 776425d..0699bb0 100644 (file)
@@ -42,14 +42,14 @@ public:
 
       /* - Send the task to the @ref worker */
       char* payload = bprintf("%f", comp_size);
-      simgrid::s4u::this_actor::send(mailbox, payload, comm_size);
+      mailbox->send(payload, comm_size);
     }
 
     XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over.");
     for (int i = 0; i < workers_count; i++) {
       /* - Eventually tell all the workers to stop by sending a "finalize" task */
       mailbox = simgrid::s4u::Mailbox::byName(std::string("worker-") + std::to_string(i % workers_count));
-      simgrid::s4u::this_actor::send(mailbox, xbt_strdup("finalize"), 0);
+      mailbox->send(xbt_strdup("finalize"), 0);
     }
   }
 };
index c2d375b..0bbedb0 100644 (file)
@@ -36,7 +36,7 @@ public:
     if (rank == 0) {
       /* The root process (rank 0) first sends the token then waits to receive it back */
       XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->name());
-      simgrid::s4u::this_actor::send(neighbor_mailbox, xbt_strdup("Token"), task_comm_size);
+      neighbor_mailbox->send(xbt_strdup("Token"), task_comm_size);
       char* res = static_cast<char*>(simgrid::s4u::this_actor::recv(my_mailbox));
       XBT_INFO("Host \"%u\" received \"%s\"", rank, res);
       xbt_free(res);
@@ -44,7 +44,7 @@ public:
       char* res = static_cast<char*>(simgrid::s4u::this_actor::recv(my_mailbox));
       XBT_INFO("Host \"%u\" received \"%s\"", rank, res);
       XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->name());
-      simgrid::s4u::this_actor::send(neighbor_mailbox, res, task_comm_size);
+      neighbor_mailbox->send(res, task_comm_size);
     }
   }
 };
index 8669478..b45d468 100644 (file)
@@ -112,7 +112,7 @@ void Node::notifyAndQuit()
 
   XBT_DEBUG("Sending a 'PREDECESSOR_LEAVING' to my successor %d", fingers_[0]);
   try {
-    simgrid::s4u::this_actor::send(simgrid::s4u::Mailbox::byName(std::to_string(fingers_[0])), pred_msg, 10, timeout);
+    simgrid::s4u::Mailbox::byName(std::to_string(fingers_[0]))->send(pred_msg, 10, timeout);
   } catch (xbt_ex& e) {
     if (e.category == timeout_error) {
       XBT_DEBUG("Timeout expired when sending a 'PREDECESSOR_LEAVING' to my successor %d", fingers_[0]);
@@ -128,7 +128,7 @@ void Node::notifyAndQuit()
     XBT_DEBUG("Sending a 'SUCCESSOR_LEAVING' to my predecessor %d", pred_id_);
 
     try {
-      simgrid::s4u::this_actor::send(simgrid::s4u::Mailbox::byName(std::to_string(pred_id_)), succ_msg, 10, timeout);
+      simgrid::s4u::Mailbox::byName(std::to_string(pred_id_))->send(succ_msg, 10, timeout);
     } catch (xbt_ex& e) {
       if (e.category == timeout_error) {
         XBT_DEBUG("Timeout expired when sending a 'SUCCESSOR_LEAVING' to my predecessor %d", pred_id_);
@@ -220,7 +220,7 @@ void Node::checkPredecessor()
 
   XBT_DEBUG("Sending a 'Predecessor Alive' request to my predecessor %d", pred_id_);
   try {
-    simgrid::s4u::this_actor::send(mailbox, message, 10, timeout);
+    mailbox->send(message, 10, timeout);
   } catch (xbt_ex& e) {
     if (e.category == timeout_error) {
       XBT_DEBUG("Failed to send the 'Predecessor Alive' request to %d", pred_id_);
@@ -231,7 +231,7 @@ void Node::checkPredecessor()
   // receive the answer
   XBT_DEBUG("Sent 'Predecessor Alive' request to %d, waiting for the answer on my mailbox '%s'", pred_id_,
             message->answer_to->name());
-  simgrid::s4u::CommPtr comm = simgrid::s4u::this_actor::irecv(return_mailbox, &data);
+  simgrid::s4u::CommPtr comm = return_mailbox->recv_async(&data);
 
   try {
     comm->wait(timeout);
@@ -264,7 +264,7 @@ int Node::remoteGetPredecessor(int ask_to)
   // send a "Get Predecessor" request to ask_to_id
   XBT_DEBUG("Sending a 'Get Predecessor' request to %d", ask_to);
   try {
-    simgrid::s4u::this_actor::send(mailbox, message, 10, timeout);
+    mailbox->send(message, 10, timeout);
   } catch (xbt_ex& e) {
     if (e.category == timeout_error) {
       XBT_DEBUG("Failed to send the 'Get Predecessor' request to %d", ask_to);
@@ -276,7 +276,7 @@ int Node::remoteGetPredecessor(int ask_to)
   // receive the answer
   XBT_DEBUG("Sent 'Get Predecessor' request to %d, waiting for the answer on my mailbox '%s'", ask_to,
             message->answer_to->name());
-  simgrid::s4u::CommPtr comm = simgrid::s4u::this_actor::irecv(return_mailbox, &data);
+  simgrid::s4u::CommPtr comm = return_mailbox->recv_async(&data);
 
   try {
     comm->wait(timeout);
@@ -340,7 +340,7 @@ int Node::remoteFindSuccessor(int ask_to, int id)
   // send a "Find Successor" request to ask_to_id
   XBT_DEBUG("Sending a 'Find Successor' request to %d for id %d", ask_to, id);
   try {
-    simgrid::s4u::this_actor::send(mailbox, message, 10, timeout);
+    mailbox->send(message, 10, timeout);
   } catch (xbt_ex& e) {
     if (e.category == timeout_error) {
       XBT_DEBUG("Failed to send the 'Find Successor' request to %d for id %d", ask_to, id_);
@@ -350,7 +350,7 @@ int Node::remoteFindSuccessor(int ask_to, int id)
   }
   // receive the answer
   XBT_DEBUG("Sent a 'Find Successor' request to %d for key %d, waiting for the answer", ask_to, id);
-  simgrid::s4u::CommPtr comm = simgrid::s4u::this_actor::irecv(return_mailbox, &data);
+  simgrid::s4u::CommPtr comm = return_mailbox->recv_async(&data);
 
   try {
     comm->wait(timeout);
@@ -389,7 +389,7 @@ void Node::remoteNotify(int notify_id, int predecessor_candidate_id)
   // send a "Notify" request to notify_id
   XBT_DEBUG("Sending a 'Notify' request to %d", notify_id);
   simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(std::to_string(notify_id));
-  simgrid::s4u::this_actor::isend(mailbox, message, 10)->detach();
+  mailbox->send_init(message, 10)->detach();
 }
 
 /* This function is called periodically. It checks the immediate successor of the current node. */
@@ -431,14 +431,14 @@ void Node::handleMessage(ChordMessage* message)
       message->answer_id = fingers_[0];
       XBT_DEBUG("Sending back a 'Find Successor Answer' to %s (mailbox %s): the successor of %d is %d",
           message->issuer_host_name.c_str(), message->answer_to->name(), message->request_id, message->answer_id);
-      simgrid::s4u::this_actor::isend(message->answer_to, message, 10)->detach();
+      message->answer_to->send_init(message, 10)->detach();
     } else {
       // otherwise, forward the request to the closest preceding finger in my table
       int closest = closestPrecedingFinger(message->request_id);
       XBT_DEBUG("Forwarding the 'Find Successor' request for id %d to my closest preceding finger %d",
           message->request_id, closest);
       simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(std::to_string(closest));
-      simgrid::s4u::this_actor::isend(mailbox, message, 10)->detach();
+      mailbox->send_init(message, 10)->detach();
     }
     break;
 
@@ -448,7 +448,7 @@ void Node::handleMessage(ChordMessage* message)
     message->answer_id = pred_id_;
     XBT_DEBUG("Sending back a 'Get Predecessor Answer' to %s via mailbox '%s': my predecessor is %d",
         message->issuer_host_name.c_str(), message->answer_to->name(), message->answer_id);
-    simgrid::s4u::this_actor::isend(message->answer_to, message, 10)->detach();
+    message->answer_to->send_init(message, 10)->detach();
     break;
 
   case NOTIFY:
@@ -486,7 +486,7 @@ void Node::handleMessage(ChordMessage* message)
     message->type = PREDECESSOR_ALIVE_ANSWER;
     XBT_DEBUG("Sending back a 'Predecessor Alive Answer' to %s (mailbox %s)",
         message->issuer_host_name.c_str(), message->answer_to->name());
-    simgrid::s4u::this_actor::isend(message->answer_to, message, 10)->detach();
+    message->answer_to->send_init(message, 10)->detach();
     break;
 
   default:
index 9d76438..209aabc 100644 (file)
@@ -128,7 +128,7 @@ public:
     simgrid::s4u::CommPtr comm_receive = nullptr;
     while ((now < (start_time_ + deadline_)) && now < MAX_SIMULATION_TIME) {
       if (comm_receive == nullptr)
-        comm_receive = simgrid::s4u::this_actor::irecv(mailbox_, &data);
+        comm_receive = mailbox_->recv_async(&data);
       while ((now < (start_time_ + deadline_)) && now < MAX_SIMULATION_TIME && not comm_receive->test()) {
         // no task was received: make some periodic calls
         if (now >= next_stabilize_date) {
index 333bd9c..c205e6c 100644 (file)
@@ -306,18 +306,23 @@ template <class Rep, class Period> inline void sleep_for(std::chrono::duration<R
    *
    * See \ref Comm for the full communication API (including non blocking communications).
    */
-  XBT_PUBLIC(void*) recv(MailboxPtr chan);
-  XBT_PUBLIC(void*) recv(MailboxPtr chan, double timeout);
-  XBT_PUBLIC(CommPtr) irecv(MailboxPtr chan, void** data);
+  XBT_PUBLIC(void*) XBT_ATTRIB_DEPRECATED("Please use Mailbox::recv") recv(MailboxPtr chan);                 // 3.17
+  XBT_PUBLIC(void*) XBT_ATTRIB_DEPRECATED("Please use Mailbox::recv") recv(MailboxPtr chan, double timeout); // 3.17
+  XBT_PUBLIC(CommPtr)
+  XBT_ATTRIB_DEPRECATED("Please use Mailbox::recv_async") irecv(MailboxPtr chan, void** data); // 3.17
 
   /** 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).
   */
-  XBT_PUBLIC(void) send(MailboxPtr chan, void* payload, double simulatedSize);
-  XBT_PUBLIC(void) send(MailboxPtr chan, void* payload, double simulatedSize, double timeout);
-
-  XBT_PUBLIC(CommPtr) isend(MailboxPtr chan, void* payload, double simulatedSize);
+  XBT_PUBLIC(void)
+  XBT_ATTRIB_DEPRECATED("Please use Mailbox::send") send(MailboxPtr chan, void* payload, double simulatedSize); // 3.17
+  XBT_PUBLIC(void)
+  XBT_ATTRIB_DEPRECATED("Please use Mailbox::send")
+  send(MailboxPtr chan, void* payload, double simulatedSize, double timeout); // 3.17
+
+  XBT_PUBLIC(CommPtr)
+  XBT_ATTRIB_DEPRECATED("Please use Mailbox::send_async") isend(MailboxPtr chan, void* payload, double simulatedSize);
 
   /** @brief Returns the actor ID of the current actor (same as pid). */
   XBT_PUBLIC(aid_t) pid();
index 1975d6e..2032de7 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <simgrid/forward.h>
 #include <simgrid/s4u/Activity.hpp>
+#include <simgrid/s4u/Mailbox.hpp> // DEPRECATED 3.17
 #include <simgrid/s4u/forward.hpp>
 
 #include <vector>
@@ -26,6 +27,7 @@ XBT_PUBLIC_CLASS Comm : public Activity
 public:
   friend void intrusive_ptr_release(simgrid::s4u::Comm * c);
   friend void intrusive_ptr_add_ref(simgrid::s4u::Comm * c);
+  friend Mailbox; // Factory of comms
 
   virtual ~Comm();
 
@@ -53,13 +55,35 @@ public:
     return idx;
   }
   /** Creates (but don't start) an async send to the mailbox @p dest */
-  static CommPtr send_init(MailboxPtr dest);
+  static CommPtr XBT_ATTRIB_DEPRECATED("please use Mailbox::send_init") // 3.17
+      send_init(MailboxPtr dest)
+  {
+    return dest->send_init();
+  }
+  /** Creates (but don't start) an async send to the mailbox @p dest */
+  static CommPtr XBT_ATTRIB_DEPRECATED("please use Mailbox::send_init") // 3.17
+      send_init(MailboxPtr dest, void* data, int simulatedByteAmount)
+  {
+    return dest->send_init(data, simulatedByteAmount);
+  }
   /** Creates and start an async send to the mailbox @p dest */
-  static CommPtr send_async(MailboxPtr dest, void* data, int simulatedByteAmount);
+  static CommPtr XBT_ATTRIB_DEPRECATED("please use Mailbox::send_async") // 3.17
+      send_async(MailboxPtr dest, void* data, int simulatedByteAmount)
+  {
+    return dest->send_async(data, simulatedByteAmount);
+  }
   /** Creates (but don't start) an async recv onto the mailbox @p from */
-  static CommPtr recv_init(MailboxPtr from);
+  static CommPtr XBT_ATTRIB_DEPRECATED("please use Mailbox::recv_init") // 3.17
+      recv_init(MailboxPtr from)
+  {
+    return from->recv_init();
+  }
   /** Creates and start an async recv to the mailbox @p from */
-  static CommPtr recv_async(MailboxPtr from, void** data);
+  static CommPtr XBT_ATTRIB_DEPRECATED("please use Mailbox::recv_async") // 3.17
+      recv_async(MailboxPtr from, void** data)
+  {
+    return from->recv_async(data);
+  }
 
   void start() override;
   void wait() override;
index fdd13dd..1abc9b2 100644 (file)
@@ -148,6 +148,28 @@ public:
 
   /** Return the actor declared as permanent receiver, or nullptr if none **/
   ActorPtr receiver();
+
+  /** Creates (but don't start) an async send to that mailbox */
+  CommPtr send_init();
+  /** Creates (but don't start) an async send to that mailbox */
+  CommPtr send_init(void* data, int simulatedByteAmount);
+  /** Creates and start an async send to that mailbox */
+  CommPtr send_async(void* data, int simulatedByteAmount);
+
+  /** Blocking send */
+  void send(void* payload, double simulatedSize);
+  /** Blocking send with timeout */
+  void send(void* payload, double simulatedSize, double timeout);
+
+  /** Creates (but don't start) an async recv onto the mailbox @p from */
+  CommPtr recv_init();
+  /** Creates and start an async recv to the mailbox @p from */
+  CommPtr recv_async(void** data);
+
+  /** Blocking receive */
+  void* recv();
+  /** Blocking receive with timeout */
+  void* recv(double timeout);
 };
 
 }} // namespace simgrid::s4u
index 71cff82..8d05ad2 100644 (file)
@@ -220,48 +220,32 @@ e_smx_state_t execute(double flops) {
 }
 
 void* recv(MailboxPtr chan) {
-  void *res = nullptr;
-  CommPtr c = Comm::recv_init(chan);
-  c->setDstData(&res, sizeof(res));
-  c->wait();
-  return res;
+  return chan->recv();
 }
 
 void* recv(MailboxPtr chan, double timeout)
 {
-  void* res = nullptr;
-  CommPtr c = Comm::recv_init(chan);
-  c->setDstData(&res, sizeof(res));
-  c->wait(timeout);
-  return res;
+  return chan->recv(timeout);
 }
 
 void send(MailboxPtr chan, void* payload, double simulatedSize)
 {
-  CommPtr c = Comm::send_init(chan);
-  c->setRemains(simulatedSize);
-  c->setSrcData(payload);
-  // c->start() is optional.
-  c->wait();
+  chan->send(payload, simulatedSize);
 }
 
 void send(MailboxPtr chan, void* payload, double simulatedSize, double timeout)
 {
-  CommPtr c = Comm::send_init(chan);
-  c->setRemains(simulatedSize);
-  c->setSrcData(payload);
-  // c->start() is optional.
-  c->wait(timeout);
+  chan->send(payload, simulatedSize, timeout);
 }
 
 CommPtr isend(MailboxPtr chan, void* payload, double simulatedSize)
 {
-  return Comm::send_async(chan, payload, simulatedSize);
+  return chan->send_async(payload, simulatedSize);
 }
 
 CommPtr irecv(MailboxPtr chan, void** data)
 {
-  return Comm::recv_async(chan, data);
+  return chan->recv_async(data);
 }
 
 aid_t pid()
index 6ab47ce..070f7d1 100644 (file)
@@ -25,22 +25,6 @@ Comm::~Comm()
   }
 }
 
-s4u::CommPtr Comm::send_init(s4u::MailboxPtr chan)
-{
-  CommPtr res   = CommPtr(new s4u::Comm());
-  res->sender_ = SIMIX_process_self();
-  res->mailbox_ = chan;
-  return res;
-}
-
-s4u::CommPtr Comm::recv_init(s4u::MailboxPtr chan)
-{
-  CommPtr res    = CommPtr(new s4u::Comm());
-  res->receiver_ = SIMIX_process_self();
-  res->mailbox_ = chan;
-  return res;
-}
-
 void Comm::setRate(double rate) {
   xbt_assert(state_==inited);
   rate_ = rate;
@@ -146,24 +130,7 @@ void Comm::detach()
   xbt_assert(state_ == inited, "You cannot detach communications once they are started.");
   xbt_assert(srcBuff_ != nullptr && srcBuffSize_ != 0, "You can only detach sends, not recvs");
   detached_ = true;
-}
-
-s4u::CommPtr Comm::send_async(MailboxPtr dest, void* data, int simulatedSize)
-{
-  s4u::CommPtr res = CommPtr(s4u::Comm::send_init(dest));
-  res->setRemains(simulatedSize);
-  res->srcBuff_     = data;
-  res->srcBuffSize_ = sizeof(void*);
-  res->start();
-  return res;
-}
-
-s4u::CommPtr Comm::recv_async(MailboxPtr dest, void** data)
-{
-  s4u::CommPtr res = CommPtr(s4u::Comm::recv_init(dest));
-  res->setDstData(data, sizeof(*data));
-  res->start();
-  return res;
+  start();
 }
 
 void Comm::cancel()
index 2882051..9642de0 100644 (file)
@@ -1,14 +1,14 @@
-/* Copyright (c) 2006-2015. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "xbt/log.h"
+#include "simgrid/s4u/Comm.hpp"
+#include "simgrid/s4u/Mailbox.hpp"
 #include "src/msg/msg_private.h"
 #include "src/simix/ActorImpl.hpp"
 #include "src/simix/smx_network_private.h"
-#include "simgrid/s4u/Mailbox.hpp"
+#include "xbt/log.h"
 
 XBT_LOG_EXTERNAL_CATEGORY(s4u);
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_channel,s4u,"S4U Communication Mailboxes");
@@ -64,5 +64,74 @@ ActorPtr Mailbox::receiver() {
   return pimpl_->permanent_receiver->iface();
 }
 
+CommPtr Mailbox::send_init()
+{
+  CommPtr res   = CommPtr(new s4u::Comm());
+  res->sender_  = SIMIX_process_self();
+  res->mailbox_ = this;
+  return res;
+}
+s4u::CommPtr Mailbox::send_init(void* data, int simulatedSize)
+{
+  s4u::CommPtr res = send_init();
+  res->setRemains(simulatedSize);
+  res->srcBuff_     = data;
+  res->srcBuffSize_ = sizeof(void*);
+  return res;
+}
+s4u::CommPtr Mailbox::send_async(void* data, int simulatedSize)
+{
+  s4u::CommPtr res = send_init(data, simulatedSize);
+  res->start();
+  return res;
+}
+void Mailbox::send(void* payload, double simulatedSize)
+{
+  CommPtr c = send_init();
+  c->setRemains(simulatedSize);
+  c->setSrcData(payload);
+  c->wait();
+}
+/** Blocking send with timeout */
+void Mailbox::send(void* payload, double simulatedSize, double timeout)
+{
+  CommPtr c = send_init();
+  c->setRemains(simulatedSize);
+  c->setSrcData(payload);
+  // c->start() is optional.
+  c->wait(timeout);
+}
+
+s4u::CommPtr Mailbox::recv_init()
+{
+  CommPtr res    = CommPtr(new s4u::Comm());
+  res->receiver_ = SIMIX_process_self();
+  res->mailbox_  = this;
+  return res;
+}
+s4u::CommPtr Mailbox::recv_async(void** data)
+{
+  s4u::CommPtr res = recv_init();
+  res->setDstData(data, sizeof(*data));
+  res->start();
+  return res;
+}
+
+void* Mailbox::recv()
+{
+  void* res = nullptr;
+  CommPtr c = recv_init();
+  c->setDstData(&res, sizeof(res));
+  c->wait();
+  return res;
+}
+void* Mailbox::recv(double timeout)
+{
+  void* res = nullptr;
+  CommPtr c = recv_init();
+  c->setDstData(&res, sizeof(res));
+  c->wait(timeout);
+  return res;
+}
 }
 }
index bad54f1..42f5214 100644 (file)
@@ -56,32 +56,32 @@ static void sender(std::vector<std::string> args)
     switch (args[0][test - 1]) {
       case 'r':
         XBT_INFO("Test %d: r (regular send)", test);
-        simgrid::s4u::this_actor::send(mbox, (void*)mboxName, 42.0);
+        mbox->send((void*)mboxName, 42.0);
         break;
       case 'R':
         XBT_INFO("Test %d: R (sleep + regular send)", test);
         simgrid::s4u::this_actor::sleep_for(0.5);
-        simgrid::s4u::this_actor::send(mbox, (void*)mboxName, 42.0);
+        mbox->send((void*)mboxName, 42.0);
         break;
 
       case 'i':
         XBT_INFO("Test %d: i (asynchronous isend)", test);
-        simgrid::s4u::this_actor::isend(mbox, (void*)mboxName, 42.0)->wait();
+        mbox->send_async((void*)mboxName, 42.0)->wait();
         break;
       case 'I':
         XBT_INFO("Test %d: I (sleep + isend)", test);
         simgrid::s4u::this_actor::sleep_for(0.5);
-        simgrid::s4u::this_actor::isend(mbox, (void*)mboxName, 42.0)->wait();
+        mbox->send_async((void*)mboxName, 42.0)->wait();
         break;
 
       case 'd':
         XBT_INFO("Test %d: d (detached send)", test);
-        simgrid::s4u::this_actor::isend(mbox, (void*)mboxName, 42.0)->detach();
+        mbox->send_init((void*)mboxName, 42.0)->detach();
         break;
       case 'D':
         XBT_INFO("Test %d: D (sleep + detached send)", test);
         simgrid::s4u::this_actor::sleep_for(0.5);
-        simgrid::s4u::this_actor::isend(mbox, (void*)mboxName, 42.0)->detach();
+        mbox->send_init((void*)mboxName, 42.0)->detach();
         break;
       default:
         xbt_die("Unknown sender spec for test %d: '%c'", test, args[0][test - 1]);
@@ -109,39 +109,39 @@ static void receiver(std::vector<std::string> args)
       case 'R':
         XBT_INFO("Test %d: R (sleep + regular receive)", test);
         simgrid::s4u::this_actor::sleep_for(0.5);
-        received = simgrid::s4u::this_actor::recv(mbox);
+        received = mbox->recv();
         break;
 
       case 'i':
         XBT_INFO("Test %d: i (asynchronous irecv)", test);
-        simgrid::s4u::this_actor::irecv(mbox, &received)->wait();
+        mbox->recv_async(&received)->wait();
         break;
       case 'I':
         XBT_INFO("Test %d: I (sleep + asynchronous irecv)", test);
         simgrid::s4u::this_actor::sleep_for(0.5);
-        simgrid::s4u::this_actor::irecv(mbox, &received)->wait();
+        mbox->recv_async(&received)->wait();
         break;
       case 'p':
         XBT_INFO("Test %d: p (regular receive on permanent mailbox)", test);
         mbox->setReceiver(Actor::self());
-        received = simgrid::s4u::this_actor::recv(mbox);
+        received = mbox->recv();
         break;
       case 'P':
         XBT_INFO("Test %d: P (sleep + regular receive on permanent mailbox)", test);
         simgrid::s4u::this_actor::sleep_for(0.5);
         mbox->setReceiver(Actor::self());
-        received = simgrid::s4u::this_actor::recv(mbox);
+        received = mbox->recv();
         break;
       case 'j':
         XBT_INFO("Test %d: j (irecv on permanent mailbox)", test);
         mbox->setReceiver(Actor::self());
-        simgrid::s4u::this_actor::irecv(mbox, &received)->wait();
+        mbox->recv_async(&received)->wait();
         break;
       case 'J':
         XBT_INFO("Test %d: J (sleep + irecv on permanent mailbox)", test);
         simgrid::s4u::this_actor::sleep_for(0.5);
         mbox->setReceiver(Actor::self());
-        simgrid::s4u::this_actor::irecv(mbox, &received)->wait();
+        mbox->recv_async(&received)->wait();
         break;
       default:
         xbt_die("Unknown receiver spec for test %d: '%c'", test, args[0][test - 1]);
index 50303b1..a5e1d5c 100644 (file)
@@ -21,7 +21,7 @@ static void receiver()
   XBT_INFO("Placing %d asynchronous recv requests", NUM_COMMS);
   void* data;
   for (int i = 0; i < NUM_COMMS; i++) {
-    simgrid::s4u::CommPtr comm = simgrid::s4u::Comm::recv_async(mymailbox, &data);
+    simgrid::s4u::CommPtr comm = mymailbox->recv_async(&data);
     pending_comms.push_back(comm);
   }
 
@@ -44,7 +44,7 @@ static void sender()
 
   for (int i = 0; i < NUM_COMMS; i++) {
     XBT_INFO("Sending a message to the receiver");
-    simgrid::s4u::this_actor::send(theirmailbox, &data, 4);
+    theirmailbox->send(&data, 4);
     XBT_INFO("Sleeping for 1000 seconds");
     simgrid::s4u::this_actor::sleep_for(1000.0);
   }
index c4ad656..2beec01 100644 (file)
@@ -17,7 +17,7 @@ static void server()
 {
   simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName("mailbox");
 
-  simgrid::s4u::CommPtr sendComm = simgrid::s4u::this_actor::isend(mailbox, xbt_strdup("Some data"), 0);
+  simgrid::s4u::CommPtr sendComm = mailbox->send_async(xbt_strdup("Some data"), 0);
 
   xbt_assert(mailbox->listen()); // True (1)
   XBT_INFO("Task listen works on regular mailboxes");
@@ -31,7 +31,7 @@ static void server()
   simgrid::s4u::MailboxPtr mailbox2 = simgrid::s4u::Mailbox::byName("mailbox2");
   mailbox2->setReceiver(simgrid::s4u::Actor::self());
 
-  simgrid::s4u::this_actor::isend(mailbox2, xbt_strdup("More data"), 0)->detach();
+  mailbox2->send_init(xbt_strdup("More data"), 0)->detach();
 
   xbt_assert(mailbox2->listen()); // used to break.
   XBT_INFO("Task listen works on asynchronous mailboxes");
index 02a5734..420540c 100644 (file)
@@ -21,7 +21,7 @@ static void sendpid()
   simgrid::s4u::this_actor::onExit((int_f_pvoid_pvoid_t)my_onexit, &pid);
 
   XBT_INFO("Sending pid of \"%d\".", pid);
-  simgrid::s4u::this_actor::send(mailbox, &pid, comm_size);
+  mailbox->send(&pid, comm_size);
   XBT_INFO("Send of pid \"%d\" done.", pid);
 
   simgrid::s4u::this_actor::suspend();
index a7316d0..1592629 100644 (file)
@@ -56,7 +56,7 @@ static void hsm_put(const char* remote_host, const char* src, const char* dest)
   XBT_INFO("%s sends %llu to %s", simgrid::s4u::this_actor::name().c_str(), read_size, remote_host);
   char* payload                    = bprintf("%s %llu", dest, read_size);
   simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(remote_host);
-  simgrid::s4u::this_actor::send(mailbox, payload, static_cast<double>(read_size));
+  mailbox->send(payload, static_cast<double>(read_size));
   simgrid::s4u::this_actor::sleep_for(.4);
 }
 
@@ -130,7 +130,7 @@ static void client()
   hsm_put("alice", "/home/doc/simgrid/examples/msg/alias/masterslave_forwarder_with_alias.c", "c:\\Windows\\tata.c");
 
   simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName("alice");
-  simgrid::s4u::this_actor::send(mailbox, xbt_strdup("finalize"), 0);
+  mailbox->send(xbt_strdup("finalize"), 0);
 
   get_set_storage_data("Disk1");
 }