summaryrefslogtreecommitdiff
path: root/gr-blocks/lib/ctrlport_probe2_b_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gr-blocks/lib/ctrlport_probe2_b_impl.cc')
-rw-r--r--gr-blocks/lib/ctrlport_probe2_b_impl.cc51
1 files changed, 19 insertions, 32 deletions
diff --git a/gr-blocks/lib/ctrlport_probe2_b_impl.cc b/gr-blocks/lib/ctrlport_probe2_b_impl.cc
index e6e2570ea6..996e997d96 100644
--- a/gr-blocks/lib/ctrlport_probe2_b_impl.cc
+++ b/gr-blocks/lib/ctrlport_probe2_b_impl.cc
@@ -63,39 +63,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<signed char>
ctrlport_probe2_b_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<signed char> buf_copy = d_buffer;
- assert(buf_copy.size() == d_len);
- mutex_buffer.unlock();
-
- return buf_copy;
+ return buffered_get.get();
}
void
ctrlport_probe2_b_impl::set_length(int len)
{
+ gr::thread::scoped_lock guard(d_setlock);
+
if(len > 8191) {
- std::cerr << "probe2_b: length " << len
- << " exceeds maximum buffer size of 8191" << std::endl;
+ GR_LOG_WARN(d_logger,
+ boost::format("probe2_b: 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
@@ -111,23 +99,22 @@ namespace gr {
{
const char *in = (const char*)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(char));
+ 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);
+ d_index = 0;
}
- mutex_buffer.unlock();
return noutput_items;
}