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.cc30
1 files changed, 18 insertions, 12 deletions
diff --git a/gr-blocks/lib/ctrlport_probe2_b_impl.cc b/gr-blocks/lib/ctrlport_probe2_b_impl.cc
index 3cf2ae0167..996e997d96 100644
--- a/gr-blocks/lib/ctrlport_probe2_b_impl.cc
+++ b/gr-blocks/lib/ctrlport_probe2_b_impl.cc
@@ -64,21 +64,26 @@ namespace gr {
}
std::vector<signed char>
- ctrlport_probe2_b_impl::get() {
+ ctrlport_probe2_b_impl::get()
+ {
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
@@ -94,20 +99,21 @@ 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
- 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) {
- buffered_get.offer_data(d_buffer);
+ if(d_index == d_len) {
+ buffered_get.offer_data(d_buffer);
+ d_index = 0;
}
return noutput_items;