31#ifndef ETL_BUFFER_DESCRIPTORS_INCLUDED
32#define ETL_BUFFER_DESCRIPTORS_INCLUDED
39#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);
103 return pdesc_item->pbuffer;
108 ETL_NODISCARD ETL_CONSTEXPR size_type max_size()
const
115 bool is_allocated()
const
117 return bool(pdesc_item->in_use);
122 bool is_released()
const
124 return bool(!pdesc_item->in_use);
129 bool is_valid()
const
131 return pdesc_item != ETL_NULLPTR;
137 pdesc_item->in_use =
false;
143 descriptor(descriptor_item* pdesc_item_)
144 : pdesc_item(pdesc_item_)
151 pdesc_item->in_use =
true;
155 descriptor_item* pdesc_item;
173 notification(descriptor desc_,
size_t count_)
181 descriptor get_descriptor()
const
188 size_t get_count()
const
200 typedef etl::delegate<void(notification)> callback_type;
203 buffer_descriptors(TBuffer* pbuffers_, callback_type callback_ = callback_type())
204 : callback(callback_)
206 for (
size_t i = 0UL; i < N_BUFFERS; ++i)
208 descriptor_items[i].pbuffer = pbuffers_ + (i * BUFFER_SIZE);
209 descriptor_items[i].in_use =
false;
214 void set_callback(
const callback_type& callback_)
216 callback = callback_;
222 for (
size_t i = 0UL; i < N_BUFFERS; ++i)
224 descriptor_items[i].in_use =
false;
232 bool is_valid()
const
234 return callback.is_valid();
238 void notify(notification n)
241 if (callback.is_valid())
249 descriptor allocate()
251 descriptor desc(&descriptor_items[next]);
253 if (desc.is_released())
269 descriptor allocate(value_type fill_)
271 descriptor desc = allocate();
275 etl::fill_n(desc.data(), BUFFER_SIZE, fill_);
284 struct descriptor_item
287 volatile flag_type in_use;
290 callback_type callback;
291 etl::array<descriptor_item, N_BUFFERS> descriptor_items;
292 etl::cyclic_value<uint_least8_t, 0U, N_BUFFERS - 1> next;
295 template <
typename TBuffer,
size_t BUFFER_SIZE_,
size_t N_BUFFERS_,
typename TFlag>
296 ETL_CONSTANT
typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type
297 buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::N_BUFFERS;
299 template <
typename TBuffer,
size_t BUFFER_SIZE_,
size_t N_BUFFERS_,
typename TFlag>
300 ETL_CONSTANT
typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type
301 buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::BUFFER_SIZE;
303 template <
typename TBuffer,
size_t BUFFER_SIZE_,
size_t N_BUFFERS_,
typename TFlag>
304 ETL_CONSTANT
typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type
305 buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::descriptor::MAX_SIZE;
bitset_ext
Definition absolute.h:40
ETL_CONSTEXPR TContainer::pointer data(TContainer &container)
Definition iterator.h:1228