diff options
Diffstat (limited to 'gr-blocks/lib/ctrlport_probe2_s_impl.cc')
-rw-r--r-- | gr-blocks/lib/ctrlport_probe2_s_impl.cc | 50 |
1 files changed, 18 insertions, 32 deletions
diff --git a/gr-blocks/lib/ctrlport_probe2_s_impl.cc b/gr-blocks/lib/ctrlport_probe2_s_impl.cc index 6a4ade462c..9924243db0 100644 --- a/gr-blocks/lib/ctrlport_probe2_s_impl.cc +++ b/gr-blocks/lib/ctrlport_probe2_s_impl.cc @@ -64,39 +64,27 @@ namespace gr { ninput_items_required[i] = d_len; } - // boost::shared_mutex mutex_buffer; - // mutable boost::mutex mutex_notify; - // boost::condition_variable condition_buffer_ready; std::vector<short> ctrlport_probe2_s_impl::get() { - mutex_buffer.lock(); - d_buffer.clear(); - mutex_buffer.unlock(); - - // wait for condition - boost::mutex::scoped_lock lock(mutex_notify); - condition_buffer_ready.wait(lock); - - mutex_buffer.lock(); - std::vector<short> buf_copy = d_buffer; - assert(buf_copy.size() == d_len); - mutex_buffer.unlock(); - - return buf_copy; + return buffered_get.get(); } void ctrlport_probe2_s_impl::set_length(int len) { + gr::thread::scoped_lock guard(d_setlock); + if(len > 8191) { - std::cerr << "probe2_s: length " << len - << " exceeds maximum buffer size of 8191" << std::endl; + GR_LOG_WARN(d_logger, + boost::format("probe2_s: length %1% exceeds maximum" + " buffer size of 8191") % len); len = 8191; } d_len = len; - d_buffer.reserve(d_len); + d_buffer.resize(d_len); + d_index = 0; } int @@ -112,23 +100,21 @@ namespace gr { { const short *in = (const short*)input_items[0]; + gr::thread::scoped_lock guard(d_setlock); + // copy samples to get buffer if we need samples - mutex_buffer.lock(); - if(d_buffer.size() < d_len) { + if(d_index < d_len) { // copy smaller of remaining buffer space and num inputs to work() - int num_copy = std::min( (int)(d_len - d_buffer.size()), noutput_items ); + int num_copy = std::min( (int)(d_len - d_index), noutput_items ); - // TODO: convert this to a copy operator for speed... - for(int i = 0; i < num_copy; i++) { - d_buffer.push_back(in[i]); - } + memcpy(&d_buffer[d_index], in, num_copy*sizeof(short)); + d_index += num_copy; + } - // notify the waiting get() if we fill up the buffer - if(d_buffer.size() == d_len) { - condition_buffer_ready.notify_one(); - } + // notify the waiting get() if we fill up the buffer + if(d_index == d_len) { + buffered_get.offer_data(d_buffer); } - mutex_buffer.unlock(); return noutput_items; } |