summaryrefslogtreecommitdiff
path: root/gr-blocks/lib
diff options
context:
space:
mode:
authorMarcus Müller <mmueller@gnuradio.org>2021-06-20 18:54:36 +0200
committermormj <34754695+mormj@users.noreply.github.com>2021-07-19 07:21:16 -0400
commitdd97527daadea86f7175c4c019dbeb96c2f47219 (patch)
treeb4753f2438c15fd75cb9dd3775cb9e6a10b96cb3 /gr-blocks/lib
parent59af4f80dc9a1406ea7b4fde3b8d547a22c951ed (diff)
blocks: Throttle consume-only mode
When throttling a sample flow, it's not necessary to produce items at the desired average rate - consuming them at a limited rate suffices to slow down the processing of the whole flow graph just as well, and avoids a copy. Signed-off-by: Marcus Müller <mmueller@gnuradio.org>
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r--gr-blocks/lib/throttle_impl.cc10
1 files changed, 7 insertions, 3 deletions
diff --git a/gr-blocks/lib/throttle_impl.cc b/gr-blocks/lib/throttle_impl.cc
index 199ddea588..201d7ce86f 100644
--- a/gr-blocks/lib/throttle_impl.cc
+++ b/gr-blocks/lib/throttle_impl.cc
@@ -32,7 +32,7 @@ throttle::sptr throttle::make(size_t itemsize, double samples_per_sec, bool igno
throttle_impl::throttle_impl(size_t itemsize, double samples_per_second, bool ignore_tags)
: sync_block("throttle",
io_signature::make(1, 1, itemsize),
- io_signature::make(1, 1, itemsize)),
+ io_signature::make(0, 1, itemsize)),
d_itemsize(itemsize),
d_ignore_tags(ignore_tags)
{
@@ -78,8 +78,12 @@ int throttle_impl::work(int noutput_items,
// copy all samples output[i] <= input[i]
const char* in = (const char*)input_items[0];
- char* out = (char*)output_items[0];
- std::memcpy(out, in, noutput_items * d_itemsize);
+
+ // iff we have a connected output, then copy
+ if (!output_items.empty()) {
+ char* out = reinterpret_cast<char*>(output_items[0]);
+ std::memcpy(out, in, noutput_items * d_itemsize);
+ }
d_total_samples += noutput_items;
auto now = std::chrono::steady_clock::now();