Notify derived class when post()ed
authorJohnathan Corgan <jcorgan@corganenterprises.com>
Tue, 4 Aug 2009 17:22:15 +0000 (10:22 -0700)
committerEric Blossom <eb@comsec.com>
Fri, 14 Aug 2009 04:40:08 +0000 (21:40 -0700)
gnuradio-core/src/lib/runtime/gr_msg_accepter.cc
gnuradio-core/src/lib/runtime/gr_tpb_detail.h

index b07f447c94caa2cb2af543441ef9d2182ce01440..ebe11870af924c5d35a742576e7905c332be0d60 100644 (file)
@@ -24,6 +24,8 @@
 #endif
 
 #include <gr_msg_accepter.h>
+#include <gr_block.h>
+#include <gr_block_detail.h>
 
 using namespace pmt;
 
@@ -40,5 +42,15 @@ gr_msg_accepter::~gr_msg_accepter()
 void
 gr_msg_accepter::post(pmt_t msg)
 {
-  d_msg_queue->insert_tail(msg);
+  // Let parent class do whatever it would have
+  gruel::msg_accepter_msgq::post(msg);
+
+  // Notify this block's scheduler a message is pending
+  gr_block *p = dynamic_cast<gr_block *>(this);
+  if (p)  
+    p->detail()->d_tpb.notify_msg();
+  else {
+    // got here somehow with a non-gr_block
+    throw std::runtime_error("gr_msg_accepter::post() - invalid derived class");
+  }
 }
index ab955240b3ad0daaad399ed12cccd1080c41b57f..29101d7307b36a6c14877c40f82b3e15616f4864 100644 (file)
@@ -35,10 +35,10 @@ struct gr_tpb_detail {
   gruel::condition_variable    input_cond;
   bool                         output_changed;
   gruel::condition_variable    output_cond;
+  bool                          msg_pending;
 
   gr_tpb_detail()
-    : input_changed(false), output_changed(false) {}
-
+    : input_changed(false), output_changed(false), msg_pending(false) { }
 
   //! Called by us to tell all our upstream blocks that their output may have changed.
   void notify_upstream(gr_block_detail *d);
@@ -57,6 +57,15 @@ struct gr_tpb_detail {
     output_changed = false;
   }
 
+  //! Called to notify us that a message is pending in the queue
+  void notify_msg()
+  {
+    gruel::scoped_lock guard(mutex);
+    msg_pending = true;
+    input_cond.notify_one();
+    output_cond.notify_one();
+  }
+
 private:
 
   //! Used by notify_downstream
@@ -74,7 +83,6 @@ private:
     output_changed = true;
     output_cond.notify_one();
   }
-
 };
 
 #endif /* INCLUDED_GR_TPB_DETAIL_H */