summaryrefslogtreecommitdiff
path: root/gr-blocks/lib
diff options
context:
space:
mode:
authorMarcus Müller <mmueller@gnuradio.org>2021-06-20 18:44:37 +0200
committermormj <34754695+mormj@users.noreply.github.com>2021-06-28 10:19:20 -0400
commita695142b33199de25327709d4983592d96e20414 (patch)
tree135068aeef5b447b30ae2a20e252f0a3f0520430 /gr-blocks/lib
parent5463e741ef6714854e4623288eb74e21eb1cca90 (diff)
blocks: zero-output, zero-copy Head mode
If you don't want to test a stream with an exact number of input, but just want your flow graph to terminate after a given number of items, having a head block without an output enables you to do that without copying the data from Head's in- to its output. Signed-off-by: Marcus Müller <mmueller@gnuradio.org>
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r--gr-blocks/lib/head_impl.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/gr-blocks/lib/head_impl.cc b/gr-blocks/lib/head_impl.cc
index 0ee22682d0..567a12d1df 100644
--- a/gr-blocks/lib/head_impl.cc
+++ b/gr-blocks/lib/head_impl.cc
@@ -1,6 +1,7 @@
/* -*- c++ -*- */
/*
* Copyright 2004,2009,2013 Free Software Foundation, Inc.
+ * Copyright 2021 Marcus Müller
*
* This file is part of GNU Radio
*
@@ -27,7 +28,7 @@ head::sptr head::make(size_t sizeof_stream_item, uint64_t nitems)
head_impl::head_impl(size_t sizeof_stream_item, uint64_t nitems)
: sync_block("head",
io_signature::make(1, 1, sizeof_stream_item),
- io_signature::make(1, 1, sizeof_stream_item)),
+ io_signature::make(0, 1, sizeof_stream_item)),
d_nitems(nitems),
d_ncopied_items(0)
{
@@ -47,7 +48,12 @@ int head_impl::work(int noutput_items,
if (n == 0)
return 0;
- memcpy(output_items[0], input_items[0], n * input_signature()->sizeof_stream_item(0));
+ // can have zero or one output port, if zero, don't copy
+ if (!output_items.empty()) {
+ memcpy(output_items[0],
+ input_items[0],
+ n * input_signature()->sizeof_stream_item(0));
+ }
d_ncopied_items += n;
return n;