Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
runtime: Add a timeout option on basic_block::delete_head_blocking
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
  • Loading branch information
smunaut committed Jan 15, 2015
1 parent 6c12138 commit 2d755af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion gnuradio-runtime/include/gnuradio/basic_block.h
Expand Up @@ -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();
Expand Down
15 changes: 12 additions & 3 deletions gnuradio-runtime/lib/basic_block.cc
Expand Up @@ -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());
Expand Down

0 comments on commit 2d755af

Please sign in to comment.