Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #290 from kovin/master
authorMartin Quinson <624847+mquinson@users.noreply.github.com>
Sun, 12 Aug 2018 15:02:11 +0000 (17:02 +0200)
committerGitHub <noreply@github.com>
Sun, 12 Aug 2018 15:02:11 +0000 (17:02 +0200)
Add method to check if a mailbox has a message ready to be consumed without having to wait

include/simgrid/s4u/Mailbox.hpp
src/s4u/s4u_Mailbox.cpp

index 8b4267a..6dd0394 100644 (file)
@@ -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();
 
index e33292e..8156900 100644 (file)
@@ -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();