From c78d307ecd5dac4e28190e5aa9b8377538f65ffa Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 24 May 2012 11:34:12 -0700 Subject: uhd: allow source work to be stopped while fg runs --- gr-uhd/lib/gr_uhd_usrp_source.cc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'gr-uhd/lib/gr_uhd_usrp_source.cc') diff --git a/gr-uhd/lib/gr_uhd_usrp_source.cc b/gr-uhd/lib/gr_uhd_usrp_source.cc index 8aa965401..99deb70c7 100644 --- a/gr-uhd/lib/gr_uhd_usrp_source.cc +++ b/gr-uhd/lib/gr_uhd_usrp_source.cc @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include "gr_uhd_common.h" @@ -60,7 +62,8 @@ public: _nchan(std::max(1, stream_args.channels.size())), _stream_now(_nchan == 1), _tag_now(false), - _start_time_set(false) + _start_time_set(false), + _is_streaming(false) { if (stream_args.cpu_format == "fc32") _type = boost::make_shared(uhd::io_type_t::COMPLEX_FLOAT32); if (stream_args.cpu_format == "sc16") _type = boost::make_shared(uhd::io_type_t::COMPLEX_INT16); @@ -320,6 +323,13 @@ public: gr_vector_const_void_star &input_items, gr_vector_void_star &output_items ){ + boost::mutex::scoped_lock lock(_mutex); + + while (!_is_streaming) + { + _cond.wait(lock); + } + #ifdef GR_UHD_USE_STREAM_API //In order to allow for low-latency: //We receive all available packets without timeout. @@ -392,6 +402,9 @@ public: } bool start(void){ + boost::mutex::scoped_lock lock(_mutex); + _is_streaming = true; + #ifdef GR_UHD_USE_STREAM_API _rx_stream = _dev->get_rx_stream(_stream_args); _samps_per_packet = _rx_stream->get_max_num_samps(); @@ -436,6 +449,9 @@ public: } bool stop(void){ + boost::mutex::scoped_lock lock(_mutex); + _is_streaming = false; + _dev->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS); this->flush(); @@ -508,6 +524,10 @@ private: uhd::time_spec_t _start_time; bool _start_time_set; + + bool _is_streaming; + boost::condition_variable _cond; + boost::mutex _mutex; }; -- cgit