summaryrefslogtreecommitdiff
path: root/gr-blocks/lib/ctrlport_probe2_s_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gr-blocks/lib/ctrlport_probe2_s_impl.cc')
-rw-r--r--gr-blocks/lib/ctrlport_probe2_s_impl.cc27
1 files changed, 16 insertions, 11 deletions
diff --git a/gr-blocks/lib/ctrlport_probe2_s_impl.cc b/gr-blocks/lib/ctrlport_probe2_s_impl.cc
index d6a15faaef..9924243db0 100644
--- a/gr-blocks/lib/ctrlport_probe2_s_impl.cc
+++ b/gr-blocks/lib/ctrlport_probe2_s_impl.cc
@@ -65,21 +65,26 @@ namespace gr {
}
std::vector<short>
- ctrlport_probe2_s_impl::get() {
+ ctrlport_probe2_s_impl::get()
+ {
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
@@ -95,19 +100,19 @@ 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
- 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) {
+ if(d_index == d_len) {
buffered_get.offer_data(d_buffer);
}