Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add method to check if a mailbox has a message ready to be consumed without having...
authorKevin Piotrkowski <kevin.piotrkowski@avature.net>
Sat, 11 Aug 2018 22:16:21 +0000 (19:16 -0300)
committerKevin Piotrkowski <kevin.piotrkowski@avature.net>
Sat, 11 Aug 2018 22:16:21 +0000 (19:16 -0300)
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..b2b60de 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;
+  }
+  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();