11 #ifndef INCLUDED_GR_RUNTIME_BUFFER_H 12 #define INCLUDED_GR_RUNTIME_BUFFER_H 32 class buffer_reader_sm;
36 typedef std::function<void*(void*, const void*, std::size_t)>
mem_func_t;
57 uint64_t downstream_lcm_nitems,
58 uint32_t downstream_max_out_mult,
59 block_sptr link = block_sptr(),
60 block_sptr buf_owner = block_sptr());
82 virtual int space_available() = 0;
87 unsigned int bufsize()
const {
return d_bufsize; }
92 const char*
base()
const {
return static_cast<const char*
>(d_base); }
100 virtual void* write_pointer();
107 virtual const void* _read_pointer(
unsigned int read_index);
112 void update_write_pointer(
int nitems);
114 void set_done(
bool done);
115 bool done()
const {
return d_done; }
120 block_sptr
link() {
return block_sptr(d_link); }
122 size_t nreaders()
const {
return d_readers.size(); }
132 d_abs_write_offset = 0;
143 d_max_reader_history = std::max(d_max_reader_history, history);
144 d_has_history = (d_max_reader_history > 1);
152 void add_item_tag(
const tag_t& tag);
166 void remove_item_tag(
const tag_t& tag,
long id);
173 void prune_tags(uint64_t max_time);
177 return d_item_tags.begin();
179 std::multimap<uint64_t, tag_t>::iterator
get_tags_end() {
return d_item_tags.end(); }
182 return d_item_tags.lower_bound(x);
186 return d_item_tags.upper_bound(x);
193 virtual void post_work(
int nitems) = 0;
201 [[maybe_unused]]
unsigned read_index)
211 [[maybe_unused]]
int items_avail,
212 [[maybe_unused]]
unsigned read_index)
233 [[maybe_unused]]
bool force =
false)
245 d_cv.wait(lock, [
this]() {
return d_callback_flag ==
false; });
246 ++d_active_pointer_counter;
257 if (--d_active_pointer_counter == 0)
269 void on_unlock()
override;
286 uint64_t downstream_lcm_nitems,
337 virtual unsigned index_add(
unsigned a,
unsigned b) = 0;
342 virtual unsigned index_sub(
unsigned a,
unsigned b) = 0;
367 uint64_t downstream_lcm_nitems,
368 uint32_t downstream_max_out_mult,
uint32_t get_max_reader_output_multiple()
Definition: buffer.h:139
unsigned int bufsize() const
return size of this buffer in items
Definition: buffer.h:87
Definition: buffer_reader_sm.h:21
virtual void update_reader_block_history(unsigned history, [[maybe_unused]] int delay)
Definition: buffer.h:141
How we keep track of the readers of a gr::buffer.
Definition: buffer_reader.h:48
unsigned d_max_reader_delay
Definition: buffer.h:299
uint64_t d_write_multiple
Definition: buffer.h:329
boost::unique_lock< boost::mutex > scoped_lock
Definition: thread.h:38
size_t d_sizeof_item
Definition: buffer.h:308
char * d_base
Definition: buffer.h:294
std::shared_ptr< logger > logger_ptr
Definition: logger.h:233
uint64_t get_downstream_lcm_nitems()
Definition: buffer.h:137
bool d_callback_flag
Definition: buffer.h:325
uint32_t d_active_pointer_counter
Definition: buffer.h:326
gr::thread::mutex * mutex()
Definition: buffer.h:125
gr::thread::condition_variable d_cv
Definition: buffer.h:324
GR_RUNTIME_API buffer_reader_sptr buffer_add_reader(buffer_sptr buf, int nzero_preload, block_sptr link=block_sptr(), int delay=0)
Create a new gr::buffer_reader and attach it to buffer buf.
Definition: custom_lock.h:26
std::multimap< uint64_t, tag_t >::iterator get_tags_end()
Definition: buffer.h:179
uint64_t d_abs_write_offset
Definition: buffer.h:319
uint64_t d_downstream_lcm_nitems
Definition: buffer.h:328
gr::thread::mutex d_mutex
Definition: buffer.h:317
virtual bool input_blocked_callback([[maybe_unused]] int items_required, [[maybe_unused]] int items_avail, [[maybe_unused]] unsigned read_index)
Callback function that the scheduler will call when it determines that the input is blocked...
Definition: buffer.h:210
void reset_nitem_counter()
Definition: buffer.h:129
GR_RUNTIME_API 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())
Allocate a buffer that holds at least nitems of size sizeof_item.
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:18
bool d_has_history
Definition: buffer.h:306
gr::logger_ptr d_logger
Definition: buffer.h:69
std::multimap< uint64_t, tag_t >::iterator get_tags_upper_bound(uint64_t x)
Definition: buffer.h:184
void decrement_active()
Decrement the number of active pointers for this buffer and signal anyone waiting when the count reac...
Definition: buffer.h:253
uint32_t d_max_reader_output_multiple
Definition: buffer.h:330
virtual bool allocate_buffer([[maybe_unused]] int nitems)
Definition: buffer.h:344
std::multimap< uint64_t, tag_t >::iterator get_tags_lower_bound(uint64_t x)
Definition: buffer.h:180
uint64_t d_last_min_items_read
Definition: buffer.h:322
virtual bool output_blkd_cb_ready([[maybe_unused]] int output_multiple)
Returns true if the current thread is ready to execute output_blocked_callback(), false otherwise...
Definition: buffer.h:223
Single writer, multiple reader fifo.
Definition: buffer.h:66
GNU Radio logging wrapper.
Definition: basic_block.h:29
std::weak_ptr< block > d_link
Definition: buffer.h:310
buffer_mapping_type
Definition: buffer.h:34
size_t nreaders() const
Definition: buffer.h:122
buffer_mapping_type d_buf_map_type
Definition: buffer.h:296
size_t get_sizeof_item()
Definition: buffer.h:135
void increment_active()
Increment the number of active pointers for this buffer.
Definition: buffer.h:241
Template used to create buffer types. Note that the factory_class parameter must contain a static fun...
Definition: buffer_type.h:96
buffer_mapping_type get_mapping_type()
return the buffer's mapping type
Definition: buffer.h:77
std::multimap< uint64_t, tag_t >::iterator get_tags_begin()
Definition: buffer.h:175
transfer_type d_transfer_type
Definition: buffer.h:332
GR_RUNTIME_API long buffer_ncurrently_allocated()
returns # of buffers currently allocated
block_sptr link()
Return the block that writes to this buffer.
Definition: buffer.h:120
buffer_reader * reader(size_t index)
Definition: buffer.h:123
std::vector< buffer_reader * > d_readers
Definition: buffer.h:309
gr::logger_ptr d_debug_logger
Definition: buffer.h:70
uint64_t nitems_written()
Definition: buffer.h:127
unsigned d_max_reader_history
Definition: buffer.h:303
transfer_type
Definition: transfer_type.h:19
std::ostream & operator<<(std::ostream &os, basic_block_sptr basic_block)
Definition: basic_block.h:436
const char * base() const
return the base address of the buffer
Definition: buffer.h:92
virtual bool output_blocked_callback([[maybe_unused]] int output_multiple, [[maybe_unused]] bool force=false)
Callback function that the scheduler will call when it determines that the output is blocked...
Definition: buffer.h:232
boost::mutex mutex
Definition: thread.h:37
bool done() const
Definition: buffer.h:115
std::multimap< uint64_t, tag_t > d_item_tags
Definition: buffer.h:321
virtual bool input_blkd_cb_ready([[maybe_unused]] int items_required, [[maybe_unused]] unsigned read_index)
Returns true when the current thread is ready to call the callback, false otherwise. Note if input_blocked_callback is overridden then this function should also be overridden.
Definition: buffer.h:200
std::function< void *(void *, const void *, std::size_t)> mem_func_t
Definition: buffer.h:36
unsigned int d_bufsize
Definition: buffer.h:295
unsigned int d_write_index
Definition: buffer.h:318
boost::condition_variable condition_variable
Definition: thread.h:39
bool d_done
Definition: buffer.h:320