summaryrefslogtreecommitdiff
path: root/gr-uhd/lib/gr_uhd_usrp_source.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gr-uhd/lib/gr_uhd_usrp_source.cc')
-rw-r--r--gr-uhd/lib/gr_uhd_usrp_source.cc22
1 files changed, 21 insertions, 1 deletions
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 <stdexcept>
#include <iostream>
#include <boost/format.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/condition_variable.hpp>
#include <boost/make_shared.hpp>
#include "gr_uhd_common.h"
@@ -60,7 +62,8 @@ public:
_nchan(std::max<size_t>(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>(uhd::io_type_t::COMPLEX_FLOAT32);
if (stream_args.cpu_format == "sc16") _type = boost::make_shared<uhd::io_type_t>(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;
};