GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
buffer_double_mapped.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2020 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_GR_RUNTIME_BUFFER_DOUBLE_MAPPED_H
12 #define INCLUDED_GR_RUNTIME_BUFFER_DOUBLE_MAPPED_H
13 
14 #include <gnuradio/api.h>
15 #include <gnuradio/buffer.h>
16 #include <gnuradio/buffer_type.h>
17 #include <gnuradio/logger.h>
18 #include <gnuradio/runtime_types.h>
19 
20 namespace gr {
21 
22 class vmcircbuf;
23 
24 /*!
25  * \brief Single writer, multiple reader fifo.
26  * \ingroup internal
27  */
29 {
30 public:
31  static buffer_type type;
32 
33  static buffer_sptr make_buffer(int nitems,
34  size_t sizeof_item,
35  uint64_t downstream_lcm_nitems,
36  uint32_t downstream_max_out_mult,
37  block_sptr link = block_sptr(),
38  block_sptr buf_owner = block_sptr());
39 
42 
44 
45  /*!
46  * \brief return number of items worth of space available for writing
47  */
48  int space_available() override;
49 
50  /*!
51  * Inherited from buffer class.
52  * @param nitems is the number of items produced by the general_work() function.
53  */
54  void post_work([[maybe_unused]] int nitems) override {}
55 
56 protected:
57  /*!
58  * sets d_vmcircbuf, d_base, d_bufsize.
59  * returns true iff successful.
60  */
61  bool allocate_buffer(int nitems) override;
62 
63  unsigned index_add(unsigned a, unsigned b) override
64  {
65  unsigned s = a + b;
66 
67  if (s >= d_bufsize)
68  s -= d_bufsize;
69 
70  assert(s < d_bufsize);
71  return s;
72  }
73 
74  unsigned index_sub(unsigned a, unsigned b) override
75  {
76  int s = a - b;
77 
78  if (s < 0)
79  s += d_bufsize;
80 
81  assert((unsigned)s < d_bufsize);
82  return s;
83  }
84 
85 private:
86  friend class buffer_reader;
87 
88  friend GR_RUNTIME_API buffer_sptr make_buffer(int nitems,
89  size_t sizeof_item,
90  uint64_t downstream_lcm_nitems,
91  block_sptr link,
92  block_sptr buf_owner);
93  friend GR_RUNTIME_API buffer_sptr
95  size_t sizeof_item,
96  uint64_t downstream_lcm_nitems,
97  uint32_t downstream_max_out_mult,
98  block_sptr link,
99  block_sptr buf_owner);
100 
101  std::unique_ptr<gr::vmcircbuf> d_vmcircbuf;
102 
103  /*!
104  * \brief constructor is private. Use gr_make_buffer to create instances.
105  *
106  * Allocate a buffer that holds at least \p nitems of size \p sizeof_item.
107  *
108  * \param nitems is the minimum number of items the buffer will hold.
109  * \param sizeof_item is the size of an item in bytes.
110  * \param downstream_lcm_nitems is the least common multiple of the items to
111  * read by downstream blocks
112  * \param downstream_max_out_mult is the maximum output multiple of all
113  * downstream blocks
114  * \param link is the block that writes to this buffer.
115  *
116  * The total size of the buffer will be rounded up to a system
117  * dependent boundary. This is typically the system page size, but
118  * under MS windows is 64KB.
119  */
120  buffer_double_mapped(int nitems,
121  size_t sizeof_item,
122  uint64_t downstream_lcm_nitems,
123  uint32_t downstream_max_out_mult,
124  block_sptr link);
125 };
126 
127 } /* namespace gr */
128 
129 
130 #endif /* INCLUDED_GR_RUNTIME_BUFFER_DOUBLE_MAPPED_H */
Single writer, multiple reader fifo.
Definition: buffer_double_mapped.h:29
unsigned index_sub(unsigned a, unsigned b) override
Decrement read or write index for this buffer.
Definition: buffer_double_mapped.h:74
unsigned index_add(unsigned a, unsigned b) override
Increment read or write index for this buffer.
Definition: buffer_double_mapped.h:63
friend GR_RUNTIME_API buffer_sptr make_buffer(int nitems, size_t sizeof_item, uint64_t downstream_lcm_nitems, block_sptr link, block_sptr buf_owner)
friend 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 buf_owner)
~buffer_double_mapped() override
bool allocate_buffer(int nitems) override
gr::logger_ptr d_debug_logger
Definition: buffer_double_mapped.h:41
gr::logger_ptr d_logger
Definition: buffer_double_mapped.h:40
void post_work([[maybe_unused]] int nitems) override
Definition: buffer_double_mapped.h:54
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())
static buffer_type type
Definition: buffer_double_mapped.h:31
int space_available() override
return number of items worth of space available for writing
How we keep track of the readers of a gr::buffer.
Definition: buffer_reader.h:49
Base class for describing a buffer's type.
Definition: buffer_type.h:28
Single writer, multiple reader fifo.
Definition: buffer.h:67
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:18
GNU Radio logging wrapper.
Definition: basic_block.h:29
std::shared_ptr< logger > logger_ptr
Definition: logger.h:250