Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: use std::function for callback logic #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/make-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ jobs:
include:
- distro: 'Ubuntu 20.04'
containerid: 'gnuradio/ci:ubuntu-20.04-3.9'
cxxflags: -Werror -Wno-error=invalid-pch
cxxflags: -Werror -Wno-error=invalid-pch -Wno-error=unused-parameter
- distro: 'Fedora 33'
containerid: 'gnuradio/ci:fedora-33-3.9'
cxxflags: ''
- distro: 'CentOS 8.3'
containerid: 'gnuradio/ci:centos-8.3-3.9'
cxxflags: -Werror
cxxflags: -Werror -Wno-error=unused-parameter
- distro: 'Debian 10'
containerid: 'gnuradio/ci-debian-10-3.9:1.0'
cxxflags: -Werror
Expand Down
8 changes: 8 additions & 0 deletions gnuradio-runtime/include/gnuradio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ install(FILES
block_gateway.h
block_registry.h
buffer.h
buffer_context.h
buffer_double_mapped.h
buffer_reader.h
buffer_reader_sm.h
buffer_single_mapped.h
buffer_type.h
constants.h
custom_lock.h
endianness.h
expj.h
flowgraph.h
Expand All @@ -30,6 +37,7 @@ install(FILES
gr_complex.h
hier_block2.h
high_res_timer.h
host_buffer.h
integer_math.h
io_signature.h
logger.h
Expand Down
12 changes: 12 additions & 0 deletions gnuradio-runtime/include/gnuradio/basic_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ class GR_RUNTIME_API basic_block : public msg_accepter,
// Message passing interface
pmt::pmt_t d_message_subscribers;

/*!
* \brief This is meant to be called by derived classes (e.g. block) to get
* a shared pointer internally. This is needed because
* std::enable_shared_from_this doesn't seem to work with derived classes
* in an inheritance hierarchy.
*/
template <typename Derived>
std::shared_ptr<Derived> shared_from_base()
{
return std::static_pointer_cast<Derived>(shared_from_this());
}

public:
pmt::pmt_t message_subscribers(pmt::pmt_t port);
~basic_block() override;
Expand Down
39 changes: 39 additions & 0 deletions gnuradio-runtime/include/gnuradio/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
#ifndef INCLUDED_GR_RUNTIME_BLOCK_H
#define INCLUDED_GR_RUNTIME_BLOCK_H

#include <memory>

#include <gnuradio/api.h>
#include <gnuradio/basic_block.h>
#include <gnuradio/buffer_type.h>
#include <gnuradio/config.h>
#include <gnuradio/logger.h>
#include <gnuradio/tags.h>
Expand Down Expand Up @@ -514,6 +517,32 @@ class GR_RUNTIME_API block : public basic_block
*/
void set_min_output_buffer(int port, long min_output_buffer);

/*!
* \brief Allocate the block_detail and necessary output buffers for this
* block.
*/
void allocate_detail(int ninputs,
int noutputs,
const std::vector<int>& downstream_max_nitems_vec,
const std::vector<uint64_t>& downstream_lcm_nitems_vec,
const std::vector<uint32_t>& downstream_max_out_mult_vec);

// --------------- Custom buffer-related functions -------------

/*!
* \brief Replace the block's buffer with a new one owned by the block_owner
* parameter
*
* \details
* This function is used to replace the buffer on the specified output port
* of the block with a new buffer that is "owned" by the specified block. This
* function will only be called if a downstream block is using a custom buffer
* 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);

// --------------- Performance counter functions -------------

/*!
Expand Down Expand Up @@ -909,6 +938,16 @@ class GR_RUNTIME_API block : public basic_block

void enable_update_rate(bool en);

/*!
* \brief Allocate a buffer for the given output port of this block. Note
* that the downstream max number of items must be passed in to this
* function for consideration.
*/
buffer_sptr allocate_buffer(int port,
int downstream_max_nitems,
uint64_t downstream_lcm_nitems,
uint32_t downstream_max_out_mult);

std::vector<long> d_max_output_buffer;
std::vector<long> d_min_output_buffer;

Expand Down
15 changes: 15 additions & 0 deletions gnuradio-runtime/include/gnuradio/block_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#define INCLUDED_GR_RUNTIME_BLOCK_DETAIL_H

#include <gnuradio/api.h>
#include <gnuradio/buffer.h>
#include <gnuradio/buffer_reader.h>
#include <gnuradio/high_res_timer.h>
#include <gnuradio/logger.h>
#include <gnuradio/runtime_types.h>
Expand Down Expand Up @@ -193,6 +195,19 @@ class GR_RUNTIME_API block_detail
*/
int set_thread_priority(int priority);

/*!
* Post general_work() cleanup to decrement the active counts for all inputs
* and outputs.
*/
void post_work_cleanup()
{
// Decrement active counts for all inputs and outputs
for (int i = 0; i < noutputs(); i++)
output(i)->decrement_active();
for (int i = 0; i < ninputs(); i++)
input(i)->buffer()->decrement_active();
}

bool threaded; // set if thread is currently running.
gr::thread::gr_thread_t thread; // portable thread handle

Expand Down
Loading