summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sorber <david.sorber@blacklynx.tech>2021-10-18 08:54:12 -0400
committermormj <34754695+mormj@users.noreply.github.com>2021-10-25 11:27:01 -0400
commitd4bd90853f499d5b65a61b3b7bf9ecf50e68bf6b (patch)
treed1bde0753540937bf6678f0cef1734d88ed5f9ce
parent47c374211221f3c636e0be2238ef233dd353697d (diff)
runtime: replace the DEFINE_CUSTOM_BUFFER_TYPE() macro function with
some advanced template magic; also a few minor type corrections for consistency Signed-off-by: David Sorber <david.sorber@blacklynx.tech>
-rw-r--r--gnuradio-runtime/include/gnuradio/block.h5
-rw-r--r--gnuradio-runtime/include/gnuradio/buffer_double_mapped.h21
-rw-r--r--gnuradio-runtime/include/gnuradio/buffer_type.h79
-rw-r--r--gnuradio-runtime/include/gnuradio/custom_lock.h2
-rw-r--r--gnuradio-runtime/include/gnuradio/host_buffer.h11
-rw-r--r--gnuradio-runtime/include/gnuradio/io_signature.h3
-rw-r--r--gnuradio-runtime/lib/block.cc4
-rw-r--r--gnuradio-runtime/lib/buffer_double_mapped.cc17
-rw-r--r--gnuradio-runtime/lib/host_buffer.cc18
-rw-r--r--gnuradio-runtime/lib/qa_buffer.cc16
-rw-r--r--gnuradio-runtime/python/gnuradio/gr/bindings/block_python.cc2
-rw-r--r--gnuradio-runtime/python/gnuradio/gr/bindings/buffer_type_python.cc2
-rw-r--r--gnuradio-runtime/python/gnuradio/gr/bindings/io_signature_python.cc2
13 files changed, 97 insertions, 85 deletions
diff --git a/gnuradio-runtime/include/gnuradio/block.h b/gnuradio-runtime/include/gnuradio/block.h
index 5fd1316951..882a0466a8 100644
--- a/gnuradio-runtime/include/gnuradio/block.h
+++ b/gnuradio-runtime/include/gnuradio/block.h
@@ -540,8 +540,7 @@ public:
* that is incompatible with the default buffer type created by this block.
*
*/
- buffer_sptr
- replace_buffer(uint32_t src_port, uint32_t dst_port, block_sptr block_owner);
+ buffer_sptr replace_buffer(size_t src_port, size_t dst_port, block_sptr block_owner);
// --------------- Performance counter functions -------------
@@ -943,7 +942,7 @@ protected:
* that the downstream max number of items must be passed in to this
* function for consideration.
*/
- buffer_sptr allocate_buffer(int port,
+ buffer_sptr allocate_buffer(size_t port,
int downstream_max_nitems,
uint64_t downstream_lcm_nitems,
uint32_t downstream_max_out_mult);
diff --git a/gnuradio-runtime/include/gnuradio/buffer_double_mapped.h b/gnuradio-runtime/include/gnuradio/buffer_double_mapped.h
index d4bfa28ff4..99b85fcc76 100644
--- a/gnuradio-runtime/include/gnuradio/buffer_double_mapped.h
+++ b/gnuradio-runtime/include/gnuradio/buffer_double_mapped.h
@@ -22,20 +22,6 @@ namespace gr {
class vmcircbuf;
/*!
- * \brief Note this function is only used and really intended to be used in
- * qa_buffer.cc for the unit tests of buffer_double_mapped.
- *
- */
-GR_RUNTIME_API buffer_sptr make_buffer_double_mapped(int nitems,
- size_t sizeof_item,
- uint64_t downstream_lcm_nitems,
- uint32_t downstream_max_out_mult,
- block_sptr link = block_sptr(),
- block_sptr buf_owner = block_sptr());
-
-DEFINE_CUSTOM_BUFFER_TYPE(DEFAULT_NON_CUSTOM, make_buffer_double_mapped);
-
-/*!
* \brief Single writer, multiple reader fifo.
* \ingroup internal
*/
@@ -44,6 +30,13 @@ class GR_RUNTIME_API buffer_double_mapped : public buffer
public:
static buffer_type type;
+ static buffer_sptr make_buffer(int nitems,
+ size_t sizeof_item,
+ uint64_t downstream_lcm_nitems,
+ uint32_t downstream_max_out_mult,
+ block_sptr link = block_sptr(),
+ block_sptr buf_owner = block_sptr());
+
gr::logger_ptr d_logger;
gr::logger_ptr d_debug_logger;
diff --git a/gnuradio-runtime/include/gnuradio/buffer_type.h b/gnuradio-runtime/include/gnuradio/buffer_type.h
index b304899750..db8180ead0 100644
--- a/gnuradio-runtime/include/gnuradio/buffer_type.h
+++ b/gnuradio-runtime/include/gnuradio/buffer_type.h
@@ -18,20 +18,11 @@
#include <functional>
#include <mutex>
#include <string>
+#include <typeinfo>
#include <vector>
namespace gr {
-// This is the function pointer declaration for the factory-like functions
-// used to create buffer subclasses
-typedef buffer_sptr (*factory_func_ptr)(int nitems,
- size_t sizeof_item,
- uint64_t downstrea_lcm_nitems,
- uint32_t downstream_max_out_mult,
- block_sptr link,
- block_sptr buf_owner);
-
-
/*!
* \brief Base class for describing a buffer's type.
*/
@@ -45,10 +36,7 @@ public:
// Temporarily define copy constructor to work around pybind issue with
// default non-copyable function argument
- buffer_type_base(buffer_type_base const& other)
- : d_name(other.d_name), d_factory(other.d_factory)
- {
- }
+ buffer_type_base(buffer_type_base const& other) : d_name(other.d_name) {}
void operator=(buffer_type_base const&) = delete;
@@ -76,42 +64,55 @@ public:
/*!
* \brief Make and return a buffer subclass of the corresponding type
*/
- inline buffer_sptr make_buffer(int nitems,
- size_t sizeof_item,
- uint64_t downstream_lcm_nitems,
- uint32_t downstream_max_out_mult,
- block_sptr link,
- block_sptr buf_owner) const
+ virtual buffer_sptr
+ make_buffer([[maybe_unused]] int nitems,
+ [[maybe_unused]] size_t sizeof_item,
+ [[maybe_unused]] uint64_t downstream_lcm_nitems,
+ [[maybe_unused]] uint32_t downstream_max_out_mult,
+ [[maybe_unused]] block_sptr link = block_sptr(),
+ [[maybe_unused]] block_sptr buf_owner = block_sptr()) const
{
- // Delegate call to factory function
- return d_factory(nitems,
- sizeof_item,
- downstream_lcm_nitems,
- downstream_max_out_mult,
- link,
- buf_owner);
+ // NOTE: this is *never* intended to be called directly, instead the overridden
+ // version from a derived class (created from the template below) will be
+ // called.
+ return nullptr;
}
protected:
const std::string d_name;
- factory_func_ptr d_factory;
- // Protected constructor
- buffer_type_base(const char* name, factory_func_ptr factory_func)
- : d_name(name), d_factory(factory_func)
- {
- }
+ buffer_type_base(const std::string name) : d_name(name) {}
};
typedef const buffer_type_base& buffer_type;
typedef std::vector<std::reference_wrapper<const buffer_type_base>> gr_vector_buffer_type;
-#define DEFINE_CUSTOM_BUFFER_TYPE(CLASSNAME, FACTORY_FUNC_PTR) \
- class GR_RUNTIME_API buftype_##CLASSNAME : public buffer_type_base \
- { \
- public: \
- buftype_##CLASSNAME() : buffer_type_base(#CLASSNAME, FACTORY_FUNC_PTR) {} \
- };
+/*!
+ * \brief Template used to create buffer types. Note that the factory_class parameter
+ * must contain a static function make_buffer() that matches the signature below
+ * and will be used to create instances of the corresponding buffer type.
+ */
+template <typename classname, typename factory_class>
+struct buftype : public buffer_type_base {
+public:
+ using factory = factory_class;
+ buffer_sptr make_buffer(int nitems,
+ size_t sizeof_item,
+ uint64_t downstream_lcm_nitems,
+ uint32_t downstream_max_out_mult,
+ block_sptr link = block_sptr(),
+ block_sptr buf_owner = block_sptr()) const override
+ {
+ return factory::make_buffer(nitems,
+ sizeof_item,
+ downstream_lcm_nitems,
+ downstream_max_out_mult,
+ link,
+ buf_owner);
+ }
+
+ buftype<classname, factory_class>() : buffer_type_base(typeid(classname).name()) {}
+};
} // namespace gr
diff --git a/gnuradio-runtime/include/gnuradio/custom_lock.h b/gnuradio-runtime/include/gnuradio/custom_lock.h
index 5011abe5eb..b8d9ed6d47 100644
--- a/gnuradio-runtime/include/gnuradio/custom_lock.h
+++ b/gnuradio-runtime/include/gnuradio/custom_lock.h
@@ -67,4 +67,4 @@ private:
} /* namespace gr */
-#endif /* INCLUDED_GR_CUSTOM_LOCK_H */ \ No newline at end of file
+#endif /* INCLUDED_GR_CUSTOM_LOCK_H */
diff --git a/gnuradio-runtime/include/gnuradio/host_buffer.h b/gnuradio-runtime/include/gnuradio/host_buffer.h
index ac09cdfe33..d5b7e2230b 100644
--- a/gnuradio-runtime/include/gnuradio/host_buffer.h
+++ b/gnuradio-runtime/include/gnuradio/host_buffer.h
@@ -23,6 +23,13 @@ public:
static buffer_type type;
+ static buffer_sptr make_buffer(int nitems,
+ size_t sizeof_item,
+ uint64_t downstream_lcm_nitems,
+ uint32_t downstream_max_out_mult,
+ block_sptr link = block_sptr(),
+ block_sptr buf_owner = block_sptr());
+
virtual ~host_buffer();
/*!
@@ -117,10 +124,6 @@ private:
block_sptr buf_owner);
};
-// See buffer_type.h for details on this macro. It is used here to generate
-// compile-time class representing the host_buffer classes "type".
-DEFINE_CUSTOM_BUFFER_TYPE(HOST_BUFFER, &host_buffer::make_host_buffer);
-
} // namespace gr
#endif /* INCLUDED_HOST_BUFFER_H */
diff --git a/gnuradio-runtime/include/gnuradio/io_signature.h b/gnuradio-runtime/include/gnuradio/io_signature.h
index 60ac798f79..5424e506ff 100644
--- a/gnuradio-runtime/include/gnuradio/io_signature.h
+++ b/gnuradio-runtime/include/gnuradio/io_signature.h
@@ -123,7 +123,8 @@ public:
*
* \param min_streams specify minimum number of streams (>= 0)
* \param max_streams specify maximum number of streams (>= min_streams or -1 ->
- * infinite) \param sizeof_stream_items specify the size of the items in the streams
+ * infinite)
+ * \param sizeof_stream_items specify the size of the items in the streams
* \param buftypes the type of buffer each stream will should use
*
* If there are more streams than there are entries in
diff --git a/gnuradio-runtime/lib/block.cc b/gnuradio-runtime/lib/block.cc
index 75f9dc6ae4..f2970cd667 100644
--- a/gnuradio-runtime/lib/block.cc
+++ b/gnuradio-runtime/lib/block.cc
@@ -417,7 +417,7 @@ void block::allocate_detail(int ninputs,
}
buffer_sptr
-block::replace_buffer(uint32_t src_port, uint32_t dst_port, block_sptr block_owner)
+block::replace_buffer(size_t src_port, size_t dst_port, block_sptr block_owner)
{
block_detail_sptr detail_ = detail();
buffer_sptr orig_buffer = detail_->output(src_port);
@@ -441,7 +441,7 @@ bool block::update_rate() const { return d_update_rate; }
void block::enable_update_rate(bool en) { d_update_rate = en; }
-buffer_sptr block::allocate_buffer(int port,
+buffer_sptr block::allocate_buffer(size_t port,
int downstream_max_nitems,
uint64_t downstream_lcm_nitems,
uint32_t downstream_max_out_mult)
diff --git a/gnuradio-runtime/lib/buffer_double_mapped.cc b/gnuradio-runtime/lib/buffer_double_mapped.cc
index 700ebac0c1..e5f8d716f9 100644
--- a/gnuradio-runtime/lib/buffer_double_mapped.cc
+++ b/gnuradio-runtime/lib/buffer_double_mapped.cc
@@ -31,12 +31,13 @@ namespace gr {
*
* type_size * nitems == k * page_size
*/
-static inline long minimum_buffer_items(long type_size, long page_size)
+static inline long minimum_buffer_items(size_t type_size, size_t page_size)
{
return page_size / GR_GCD(type_size, page_size);
}
-buffer_type buffer_double_mapped::type(buftype_DEFAULT_NON_CUSTOM{});
+buffer_type
+ buffer_double_mapped::type(buftype<buffer_double_mapped, buffer_double_mapped>{});
buffer_double_mapped::buffer_double_mapped(int nitems,
size_t sizeof_item,
@@ -67,12 +68,12 @@ buffer_double_mapped::buffer_double_mapped(int nitems,
// NB: Added the extra 'block_sptr unused' parameter so that the
// call signature matches the other factory-like functions used to create
// the buffer_single_mapped subclasses
-buffer_sptr make_buffer_double_mapped(int nitems,
- size_t sizeof_item,
- uint64_t downstream_lcm_nitems,
- uint32_t downstream_max_out_mult,
- block_sptr link,
- block_sptr unused)
+buffer_sptr buffer_double_mapped::make_buffer(int nitems,
+ size_t sizeof_item,
+ uint64_t downstream_lcm_nitems,
+ uint32_t downstream_max_out_mult,
+ block_sptr link,
+ block_sptr unused)
{
return buffer_sptr(new buffer_double_mapped(
nitems, sizeof_item, downstream_lcm_nitems, downstream_max_out_mult, link));
diff --git a/gnuradio-runtime/lib/host_buffer.cc b/gnuradio-runtime/lib/host_buffer.cc
index 535a7a5286..eb5d4bd515 100644
--- a/gnuradio-runtime/lib/host_buffer.cc
+++ b/gnuradio-runtime/lib/host_buffer.cc
@@ -14,8 +14,6 @@
namespace gr {
-buffer_type host_buffer::type(buftype_HOST_BUFFER{});
-
void* host_buffer::device_memcpy(void* dest, const void* src, std::size_t count)
{
// There is no spoon...er... device so fake it out using regular memcpy
@@ -28,6 +26,22 @@ void* host_buffer::device_memmove(void* dest, const void* src, std::size_t count
return std::memmove(dest, src, count);
}
+buffer_type host_buffer::type(buftype<host_buffer, host_buffer>{});
+
+buffer_sptr host_buffer::make_buffer(int nitems,
+ size_t sizeof_item,
+ uint64_t downstream_lcm_nitems,
+ uint32_t downstream_max_out_mult,
+ block_sptr link,
+ block_sptr buf_owner)
+{
+ return buffer_sptr(new host_buffer(nitems,
+ sizeof_item,
+ downstream_lcm_nitems,
+ downstream_max_out_mult,
+ link,
+ buf_owner));
+}
host_buffer::host_buffer(int nitems,
size_t sizeof_item,
diff --git a/gnuradio-runtime/lib/qa_buffer.cc b/gnuradio-runtime/lib/qa_buffer.cc
index 1c97fd070d..d787661650 100644
--- a/gnuradio-runtime/lib/qa_buffer.cc
+++ b/gnuradio-runtime/lib/qa_buffer.cc
@@ -42,8 +42,8 @@ static void t0_body()
int nitems = 4000 / sizeof(int);
int counter = 0;
- gr::buffer_sptr buf(
- gr::make_buffer_double_mapped(nitems, sizeof(int), nitems, 1, gr::block_sptr()));
+ gr::buffer_sptr buf(gr::buffer_double_mapped::make_buffer(
+ nitems, sizeof(int), nitems, 1, gr::block_sptr()));
int last_sa;
int sa;
@@ -77,8 +77,8 @@ static void t1_body()
int write_counter = 0;
int read_counter = 0;
- gr::buffer_sptr buf(
- gr::make_buffer_double_mapped(nitems, sizeof(int), nitems, 1, gr::block_sptr()));
+ gr::buffer_sptr buf(gr::buffer_double_mapped::make_buffer(
+ nitems, sizeof(int), nitems, 1, gr::block_sptr()));
gr::buffer_reader_sptr r1(gr::buffer_add_reader(buf, 0, gr::block_sptr()));
int sa;
@@ -149,8 +149,8 @@ static void t2_body()
int nitems = (64 * (1L << 10)) / sizeof(int); // 64K worth of ints
- gr::buffer_sptr buf(
- gr::make_buffer_double_mapped(nitems, sizeof(int), nitems, 1, gr::block_sptr()));
+ gr::buffer_sptr buf(gr::buffer_double_mapped::make_buffer(
+ nitems, sizeof(int), nitems, 1, gr::block_sptr()));
gr::buffer_reader_sptr r1(gr::buffer_add_reader(buf, 0, gr::block_sptr()));
int read_counter = 0;
@@ -215,8 +215,8 @@ static void t3_body()
int nitems = (64 * (1L << 10)) / sizeof(int);
static const int N = 5;
- gr::buffer_sptr buf(
- gr::make_buffer_double_mapped(nitems, sizeof(int), nitems, 1, gr::block_sptr()));
+ gr::buffer_sptr buf(gr::buffer_double_mapped::make_buffer(
+ nitems, sizeof(int), nitems, 1, gr::block_sptr()));
gr::buffer_reader_sptr reader[N];
int read_counter[N];
int write_counter = 0;
diff --git a/gnuradio-runtime/python/gnuradio/gr/bindings/block_python.cc b/gnuradio-runtime/python/gnuradio/gr/bindings/block_python.cc
index 4ba7742b15..4a602c8970 100644
--- a/gnuradio-runtime/python/gnuradio/gr/bindings/block_python.cc
+++ b/gnuradio-runtime/python/gnuradio/gr/bindings/block_python.cc
@@ -14,7 +14,7 @@
/* BINDTOOL_GEN_AUTOMATIC(0) */
/* BINDTOOL_USE_PYGCCXML(0) */
/* BINDTOOL_HEADER_FILE(block.h) */
-/* BINDTOOL_HEADER_FILE_HASH(23fce54cc3292f62ca2551fb3f409f77) */
+/* BINDTOOL_HEADER_FILE_HASH(1c265259ee70fb7b389cc57a9334a1f1) */
/***********************************************************************************/
#include <pybind11/complex.h>
diff --git a/gnuradio-runtime/python/gnuradio/gr/bindings/buffer_type_python.cc b/gnuradio-runtime/python/gnuradio/gr/bindings/buffer_type_python.cc
index 2490c815f6..a48138b3fb 100644
--- a/gnuradio-runtime/python/gnuradio/gr/bindings/buffer_type_python.cc
+++ b/gnuradio-runtime/python/gnuradio/gr/bindings/buffer_type_python.cc
@@ -14,7 +14,7 @@
/* BINDTOOL_GEN_AUTOMATIC(0) */
/* BINDTOOL_USE_PYGCCXML(0) */
/* BINDTOOL_HEADER_FILE(buffer_type.h) */
-/* BINDTOOL_HEADER_FILE_HASH(6ed358bbc956244006073acb8c2efab2) */
+/* BINDTOOL_HEADER_FILE_HASH(879f41aa2a2009fd5fb31bc24ecef768) */
/***********************************************************************************/
#include <pybind11/complex.h>
diff --git a/gnuradio-runtime/python/gnuradio/gr/bindings/io_signature_python.cc b/gnuradio-runtime/python/gnuradio/gr/bindings/io_signature_python.cc
index d6ddf570dd..8f52e311f6 100644
--- a/gnuradio-runtime/python/gnuradio/gr/bindings/io_signature_python.cc
+++ b/gnuradio-runtime/python/gnuradio/gr/bindings/io_signature_python.cc
@@ -14,7 +14,7 @@
/* BINDTOOL_GEN_AUTOMATIC(0) */
/* BINDTOOL_USE_PYGCCXML(0) */
/* BINDTOOL_HEADER_FILE(io_signature.h) */
-/* BINDTOOL_HEADER_FILE_HASH(baf27e696237b6542ec62a4c5627ea1d) */
+/* BINDTOOL_HEADER_FILE_HASH(2d21df486462de11f4eb25681101c0c6) */
/***********************************************************************************/
#include <pybind11/complex.h>