31#ifndef ETL_BUFFER_DESCRIPTORS_INCLUDED
32#define ETL_BUFFER_DESCRIPTORS_INCLUDED
38#include "static_assert.h"
51 template <
typename TBuffer,
size_t BUFFER_SIZE_,
size_t N_BUFFERS_,
typename TFlag =
bool>
52 class buffer_descriptors
56 struct descriptor_item;
60 typedef TBuffer value_type;
61 typedef value_type* pointer;
62 typedef size_t size_type;
63 typedef TFlag flag_type;
65 static ETL_CONSTANT size_type N_BUFFERS = N_BUFFERS_;
66 static ETL_CONSTANT size_type BUFFER_SIZE = BUFFER_SIZE_;
75 friend class buffer_descriptors;
77 static ETL_CONSTANT size_type MAX_SIZE = buffer_descriptors::BUFFER_SIZE;
81 : pdesc_item(ETL_NULLPTR)
86 descriptor(
const descriptor& other)
87 : pdesc_item(other.pdesc_item)
92 descriptor& operator =(
const descriptor& other)
94 pdesc_item = other.pdesc_item;
101 assert(pdesc_item != ETL_NULLPTR);
102 return pdesc_item->pbuffer;
107 ETL_CONSTEXPR size_type
max_size()
const
114 bool is_allocated()
const
116 return bool(pdesc_item->in_use);
121 bool is_released()
const
123 return bool(!pdesc_item->in_use);
128 bool is_valid()
const
130 return pdesc_item != ETL_NULLPTR;
136 pdesc_item->in_use =
false;
142 descriptor(descriptor_item* pdesc_item_)
143 : pdesc_item(pdesc_item_)
150 pdesc_item->in_use =
true;;
154 descriptor_item* pdesc_item;
172 notification(descriptor desc_,
size_t count_)
180 descriptor get_descriptor()
const
187 size_t get_count()
const
202 buffer_descriptors(TBuffer* pbuffers_, callback_type callback_ = callback_type())
203 : callback(callback_)
205 for (
size_t i = 0UL; i < N_BUFFERS; ++i)
207 descriptor_items[i].pbuffer = pbuffers_ + (i * BUFFER_SIZE);
208 descriptor_items[i].in_use =
false;
213 void set_callback(
const callback_type& callback_)
215 callback = callback_;
221 for (
size_t i = 0UL; i < N_BUFFERS; ++i)
223 descriptor_items[i].in_use =
false;
231 bool is_valid()
const
233 return callback.is_valid();
237 void notify(notification n)
240 if (callback.is_valid())
248 descriptor allocate()
250 descriptor desc(&descriptor_items[next]);
252 if (desc.is_released())
268 descriptor allocate(value_type fill_)
270 descriptor desc = allocate();
274 etl::fill_n(desc.data(), BUFFER_SIZE, fill_);
283 struct descriptor_item
286 volatile flag_type in_use;
289 callback_type callback;
294 template <
typename TBuffer,
size_t BUFFER_SIZE_,
size_t N_BUFFERS_,
typename TFlag>
295 ETL_CONSTANT
typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::N_BUFFERS;
297 template <
typename TBuffer,
size_t BUFFER_SIZE_,
size_t N_BUFFERS_,
typename TFlag>
298 ETL_CONSTANT
typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::BUFFER_SIZE;
300 template <
typename TBuffer,
size_t BUFFER_SIZE_,
size_t N_BUFFERS_,
typename TFlag>
301 ETL_CONSTANT
typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::descriptor::MAX_SIZE;
Provides a value that cycles between two limits.
Definition: cyclic_value.h:53
Declaration.
Definition: delegate_cpp03.h:175
bitset_ext
Definition: absolute.h:38
size_t max_size() const
Returns the maximum number of items in the variant_pool.
Definition: variant_pool_generator.h:281