commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 01/02: runtime: Add a timeout option on bas


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/02: runtime: Add a timeout option on basic_block::delete_head_blocking
Date: Thu, 15 Jan 2015 20:47:28 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch maint
in repository gnuradio.

commit 2d755af9cd2668a3a8f55bd14c8b598234729957
Author: Sylvain Munaut <address@hidden>
Date:   Thu Jan 15 20:50:55 2015 +0100

    runtime: Add a timeout option on basic_block::delete_head_blocking
    
    Signed-off-by: Sylvain Munaut <address@hidden>
---
 gnuradio-runtime/include/gnuradio/basic_block.h |  3 ++-
 gnuradio-runtime/lib/basic_block.cc             | 15 ++++++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/gnuradio-runtime/include/gnuradio/basic_block.h 
b/gnuradio-runtime/include/gnuradio/basic_block.h
index 066257d..da07dd9 100644
--- a/gnuradio-runtime/include/gnuradio/basic_block.h
+++ b/gnuradio-runtime/include/gnuradio/basic_block.h
@@ -254,9 +254,10 @@ namespace gr {
     pmt::pmt_t delete_head_nowait( pmt::pmt_t which_port);
 
     /*!
+     * \param[in] millisec Optional timeout value (0=no timeout)
      * \returns returns pmt at head of queue or pmt::pmt_t() if empty.
      */
-    pmt::pmt_t delete_head_blocking( pmt::pmt_t which_port);
+    pmt::pmt_t delete_head_blocking(pmt::pmt_t which_port, unsigned int 
millisec = 0);
 
     msg_queue_t::iterator get_iterator(pmt::pmt_t which_port) {
       return msg_queue[which_port].begin();
diff --git a/gnuradio-runtime/lib/basic_block.cc 
b/gnuradio-runtime/lib/basic_block.cc
index 09d2eb2..082d075 100644
--- a/gnuradio-runtime/lib/basic_block.cc
+++ b/gnuradio-runtime/lib/basic_block.cc
@@ -228,12 +228,21 @@ namespace gr {
   }
 
   pmt::pmt_t
-  basic_block::delete_head_blocking(pmt::pmt_t which_port)
+  basic_block::delete_head_blocking(pmt::pmt_t which_port, unsigned int 
millisec)
   {
     gr::thread::scoped_lock guard(mutex);
 
-    while(empty_p(which_port)) {
-      msg_queue_ready[which_port]->wait(guard);
+    if (millisec) {
+       boost::system_time const timeout = boost::get_system_time() + 
boost::posix_time::milliseconds(millisec);
+       while (empty_p(which_port)) {
+         if (!msg_queue_ready[which_port]->timed_wait(guard, timeout)) {
+           return pmt::pmt_t();
+        }
+       }
+    } else {
+      while(empty_p(which_port)) {
+        msg_queue_ready[which_port]->wait(guard);
+      }
     }
 
     pmt::pmt_t m(msg_queue[which_port].front());



reply via email to

[Prev in Thread] Current Thread [Next in Thread]