From: Martin Quinson <624847+mquinson@users.noreply.github.com> Date: Sun, 12 Aug 2018 15:02:11 +0000 (+0200) Subject: Merge pull request #290 from kovin/master X-Git-Tag: v3_21~259^2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7f1e24039c708e51889d620f29dfba9116065157?hp=0dfec40ad0e228992ff3095af88609068979496e Merge pull request #290 from kovin/master Add method to check if a mailbox has a message ready to be consumed without having to wait --- diff --git a/include/simgrid/s4u/Mailbox.hpp b/include/simgrid/s4u/Mailbox.hpp index 8b4267a86f..6dd039475b 100644 --- a/include/simgrid/s4u/Mailbox.hpp +++ b/include/simgrid/s4u/Mailbox.hpp @@ -131,6 +131,9 @@ public: /** Check if there is a communication going on in a mailbox. */ bool listen(); + /** Check if there is a communication ready to be consumed from a mailbox. */ + bool ready(); + /** Gets the first element in the queue (without dequeuing it), or nullptr if none is there */ smx_activity_t front(); diff --git a/src/s4u/s4u_Mailbox.cpp b/src/s4u/s4u_Mailbox.cpp index e33292eb30..8156900c05 100644 --- a/src/s4u/s4u_Mailbox.cpp +++ b/src/s4u/s4u_Mailbox.cpp @@ -43,6 +43,18 @@ bool Mailbox::listen() return not this->empty() || (pimpl_->permanent_receiver_ && not pimpl_->done_comm_queue_.empty()); } +bool Mailbox::ready() +{ + bool comm_ready = false; + if (not pimpl_->comm_queue_.empty()) { + comm_ready = pimpl_->comm_queue_.front()->state_ == SIMIX_DONE; + + } else if (pimpl_->permanent_receiver_ && not pimpl_->done_comm_queue_.empty()) { + comm_ready = pimpl_->done_comm_queue_.front()->state_ == SIMIX_DONE; + } + return comm_ready; +} + smx_activity_t Mailbox::front() { return pimpl_->comm_queue_.empty() ? nullptr : pimpl_->comm_queue_.front();