Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make s4u::Mailbox::setReceiver() working; add s4u::Actor::self()
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 31 Jul 2016 20:16:08 +0000 (22:16 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 31 Jul 2016 20:16:08 +0000 (22:16 +0200)
include/simgrid/s4u/Actor.hpp
include/simgrid/s4u/mailbox.hpp
src/msg/msg_mailbox.cpp
src/s4u/s4u_actor.cpp
src/s4u/s4u_mailbox.cpp

index f9dd991..34562df 100644 (file)
@@ -170,6 +170,8 @@ public:
   using Ptr = boost::intrusive_ptr<Actor>;
 
   // ***** Actor creation *****
+  /** Retrieve a reference to myself */
+  static Ptr self();
 
   /** Create an actor using a function
    *
index eea3e90..f01330b 100644 (file)
@@ -59,7 +59,7 @@ public:
    * It means that the communications sent to this mailbox will start flowing to its host even before he does a recv().
    * This models the real behavior of TCP and MPI communications, amongst other.
    */
-  void setReceiver(Actor* process);
+  void setReceiver(ActorPtr process);
 
   /** Return the process declared as permanent receiver, or nullptr if none **/
   ActorPtr receiver();
index f1fd0c3..e533c9e 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "simgrid/msg.h"
 #include "msg_private.h"
+#include "simgrid/s4u/Actor.hpp"
 #include "simgrid/s4u/mailbox.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_mailbox, msg, "Logging specific to MSG (mailbox)");
@@ -25,8 +26,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_mailbox, msg, "Logging specific to MSG (mail
  */
 void MSG_mailbox_set_async(const char *alias){
   simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(alias);
-
-  simcall_mbox_set_receiver(mailbox->getImpl(), SIMIX_process_self());
+  mailbox->setReceiver(simgrid::s4u::Actor::self());
   XBT_VERB("%s mailbox set to receive eagerly for myself\n",alias);
 }
 
index 24a6bb8..d5bf15d 100644 (file)
@@ -20,6 +20,15 @@ namespace simgrid {
 namespace s4u {
 
 // ***** Actor creation *****
+ActorPtr Actor::self()
+{
+  smx_context_t self_context = SIMIX_context_self();
+  if (self_context == nullptr)
+    return simgrid::s4u::ActorPtr();
+
+  return simgrid::s4u::ActorPtr(&self_context->process()->actor());
+}
+
 
 ActorPtr Actor::createActor(const char* name, s4u::Host *host, double killTime, std::function<void()> code)
 {
index 3f289d8..20a3bcf 100644 (file)
@@ -45,13 +45,14 @@ smx_synchro_t Mailbox::front()
   return pimpl_->comm_queue.empty() ? nullptr : pimpl_->comm_queue.front();
 }
 
-void Mailbox::setReceiver(Actor* actor) {
+void Mailbox::setReceiver(ActorPtr actor) {
   simcall_mbox_set_receiver(pimpl_, actor == nullptr ? nullptr : actor->pimpl_);
 }
 
 /** @brief get the receiver (process associated to the mailbox) */
 ActorPtr Mailbox::receiver() {
-  if(pimpl_->permanent_receiver == nullptr) return ActorPtr();
+  if(pimpl_->permanent_receiver == nullptr)
+    return ActorPtr();
   return ActorPtr(&pimpl_->permanent_receiver->actor());
 }