From 5f0fec59645a72e9126fcf3fe56677ef9331ba9d Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 31 Jul 2016 22:16:08 +0200 Subject: [PATCH 1/1] make s4u::Mailbox::setReceiver() working; add s4u::Actor::self() --- include/simgrid/s4u/Actor.hpp | 2 ++ include/simgrid/s4u/mailbox.hpp | 2 +- src/msg/msg_mailbox.cpp | 4 ++-- src/s4u/s4u_actor.cpp | 9 +++++++++ src/s4u/s4u_mailbox.cpp | 5 +++-- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index f9dd9919d7..34562df5a8 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -170,6 +170,8 @@ public: using Ptr = boost::intrusive_ptr; // ***** Actor creation ***** + /** Retrieve a reference to myself */ + static Ptr self(); /** Create an actor using a function * diff --git a/include/simgrid/s4u/mailbox.hpp b/include/simgrid/s4u/mailbox.hpp index eea3e9044b..f01330b53f 100644 --- a/include/simgrid/s4u/mailbox.hpp +++ b/include/simgrid/s4u/mailbox.hpp @@ -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(); diff --git a/src/msg/msg_mailbox.cpp b/src/msg/msg_mailbox.cpp index f1fd0c36ee..e533c9e275 100644 --- a/src/msg/msg_mailbox.cpp +++ b/src/msg/msg_mailbox.cpp @@ -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); } diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp index 24a6bb8c3d..d5bf15d794 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_actor.cpp @@ -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 code) { diff --git a/src/s4u/s4u_mailbox.cpp b/src/s4u/s4u_mailbox.cpp index 3f289d8425..20a3bcf969 100644 --- a/src/s4u/s4u_mailbox.cpp +++ b/src/s4u/s4u_mailbox.cpp @@ -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()); } -- 2.20.1