From: Kevin Piotrkowski Date: Sat, 11 Aug 2018 22:16:21 +0000 (-0300) Subject: Add method to check if a mailbox has a message ready to be consumed without having... X-Git-Tag: v3_21~259^2^2~1 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/1ed0e64dc405fbb627ff8a7d7b70ac4ff81cd489?hp=0dfec40ad0e228992ff3095af88609068979496e 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..b2b60de515 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; + } + if (!comm_ready && 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();