From cfaf71bdfb6cf3cb4d0908080b7fb67fa4d5051c Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Mon, 30 Mar 2020 15:18:32 +0200 Subject: [PATCH] add Mailox_listen_from --- include/simgrid/s4u/Mailbox.hpp | 3 +++ src/msg/msg_task.cpp | 8 +------- src/s4u/s4u_Mailbox.cpp | 9 +++++++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/simgrid/s4u/Mailbox.hpp b/include/simgrid/s4u/Mailbox.hpp index 5c02b70061..f60c07019a 100644 --- a/include/simgrid/s4u/Mailbox.hpp +++ b/include/simgrid/s4u/Mailbox.hpp @@ -45,6 +45,9 @@ public: /** Check if there is a communication going on in a mailbox. */ bool listen(); + /** Look if there is a communication going on in a mailbox and return the PID of the sender actor */ + aid_t listen_from(); + /** Check if there is a communication ready to be consumed from a mailbox. */ bool ready(); diff --git a/src/msg/msg_task.cpp b/src/msg/msg_task.cpp index 139ebc8f47..032624f3cf 100644 --- a/src/msg/msg_task.cpp +++ b/src/msg/msg_task.cpp @@ -637,13 +637,7 @@ msg_comm_t MSG_task_irecv_bounded(msg_task_t* task, const char* name, double rat */ int MSG_task_listen_from(const char* alias) { - /* looks inside the rdv directly. Not clean. */ - simgrid::kernel::activity::CommImplPtr comm = simgrid::s4u::Mailbox::by_name(alias)->front(); - - if (comm && comm->src_actor_) - return comm->src_actor_->get_pid(); - else - return -1; + return simgrid::s4u::Mailbox::by_name(alias)->listen_from(); } /** @brief Destroys the given task. diff --git a/src/s4u/s4u_Mailbox.cpp b/src/s4u/s4u_Mailbox.cpp index 190dd9d747..abbf92e21a 100644 --- a/src/s4u/s4u_Mailbox.cpp +++ b/src/s4u/s4u_Mailbox.cpp @@ -44,6 +44,15 @@ bool Mailbox::listen() return not this->empty() || (pimpl_->permanent_receiver_ && not pimpl_->done_comm_queue_.empty()); } +aid_t Mailbox::listen_from() +{ + kernel::activity::CommImplPtr comm = front(); + if (comm && comm->src_actor_) + return comm->src_actor_->get_pid(); + else + return -1; +} + bool Mailbox::ready() { bool comm_ready = false; -- 2.20.1