31#ifndef ETL_SPSC_QUEUE_LOCKED_INCLUDED
32#define ETL_SPSC_QUEUE_LOCKED_INCLUDED
48 template <
size_t MEMORY_MODEL = etl::memory_model::MEMORY_MODEL_LARGE>
49 class iqueue_spsc_locked_base
121 if (index == maximum) ETL_UNLIKELY
171#if defined(ETL_POLYMORPHIC_SPSC_QUEUE_ISR) || defined(ETL_POLYMORPHIC_CONTAINERS)
191 template <
typename T, const
size_t MEMORY_MODEL = etl::memory_model::MEMORY_MODEL_LARGE>
196 typedef iqueue_spsc_locked_base<MEMORY_MODEL> base_t;
204 typedef T&& rvalue_reference;
213 return push_implementation(value);
223 bool result = push_implementation(value);
230#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION)
237 return push_implementation(etl::move(value));
244 bool push(rvalue_reference value)
248 bool result = push_implementation(etl::move(value));
256#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION)
261 template <
typename ... Args>
264 return emplace_implementation(etl::forward<Args>(args)...);
271 template <
typename ... Args>
276 bool result = emplace_implementation(etl::forward<Args>(args)...);
287 template <
typename T1>
290 return emplace_implementation(value1);
297 template <
typename T1,
typename T2>
300 return emplace_implementation(value1, value2);
307 template <
typename T1,
typename T2,
typename T3>
310 return emplace_implementation(value1, value2, value3);
317 template <
typename T1,
typename T2,
typename T3,
typename T4>
320 return emplace_implementation(value1, value2, value3, value4);
331 bool result = emplace_implementation();
342 template <
typename T1>
347 bool result = emplace_implementation(value1);
358 template <
typename T1,
typename T2>
359 bool emplace(
const T1& value1,
const T2& value2)
363 bool result = emplace_implementation(value1, value2);
374 template <
typename T1,
typename T2,
typename T3>
375 bool emplace(
const T1& value1,
const T2& value2,
const T3& value3)
379 bool result = emplace_implementation(value1, value2, value3);
390 template <
typename T1,
typename T2,
typename T3,
typename T4>
391 bool emplace(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
395 bool result = emplace_implementation(value1, value2, value3, value4);
409 return pop_implementation(value);;
419 bool result = pop_implementation(value);
432 return pop_implementation();
442 bool result = pop_implementation();
455 return front_implementation();
464 return front_implementation();
474 reference result = front_implementation();
500 while (pop_implementation())
513 if ETL_IF_CONSTEXPR(etl::is_trivially_destructible<T>::value)
521 while (pop_implementation())
593 , p_buffer(p_buffer_)
621#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION)
626 bool push_implementation(rvalue_reference value)
630 ::new (&p_buffer[this->
write_index]) T(etl::move(value));
644#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION)
649 template <
typename ... Args>
650 bool emplace_implementation(Args&&... args)
654 ::new (&p_buffer[this->
write_index]) T(etl::forward<Args>(args)...);
670 bool emplace_implementation()
690 template <
typename T1>
691 bool emplace_implementation(
const T1& value1)
711 template <
typename T1,
typename T2>
712 bool emplace_implementation(
const T1& value1,
const T2& value2)
716 ::new (&p_buffer[this->
write_index]) T(value1, value2);
732 template <
typename T1,
typename T2,
typename T3>
733 bool emplace_implementation(
const T1& value1,
const T2& value2,
const T3& value3)
737 ::new (&p_buffer[this->
write_index]) T(value1, value2, value3);
753 template <
typename T1,
typename T2,
typename T3,
typename T4>
754 bool emplace_implementation(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
758 ::new (&p_buffer[this->
write_index]) T(value1, value2, value3, value4);
784#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION)
785 value = etl::move(p_buffer[this->
read_index]);
821 bool pop_implementation()
849 const etl::ifunction<void>& lock;
850 const etl::ifunction<void>& unlock;
861 template <
typename T,
size_t SIZE, const
size_t MEMORY_MODEL = etl::memory_model::MEMORY_MODEL_LARGE>
874 static ETL_CONSTANT size_type MAX_SIZE =
size_type(SIZE);
882 : base_t(reinterpret_cast<T*>(buffer.raw), MAX_SIZE, lock_, unlock_)
908 template <
typename T,
size_t SIZE, const
size_t MEMORY_MODEL>
Definition queue_spsc_locked.h:50
size_type available_from_unlocked() const
How much free space available in the queue.
Definition queue_spsc_locked.h:59
const size_type MAX_SIZE
Definition queue_spsc_locked.h:132
bool empty_implementation() const
Is the queue empty?
Definition queue_spsc_locked.h:163
size_type available_implementation() const
How much free space available in the queue.
Definition queue_spsc_locked.h:139
bool full_from_unlocked() const
Is the queue full?
Definition queue_spsc_locked.h:67
bool empty_from_unlocked() const
Is the queue empty?
Definition queue_spsc_locked.h:83
size_type max_size() const
How many items can the queue hold.
Definition queue_spsc_locked.h:99
size_type size_from_unlocked() const
How many items in the queue?
Definition queue_spsc_locked.h:75
size_type current_size
The current size of the queue.
Definition queue_spsc_locked.h:131
size_type write_index
Where to input new data.
Definition queue_spsc_locked.h:129
bool full_implementation() const
Is the queue full?
Definition queue_spsc_locked.h:147
etl::size_type_lookup< MEMORY_MODEL >::type size_type
The type used for determining the size of queue.
Definition queue_spsc_locked.h:54
size_type capacity() const
How many items can the queue hold.
Definition queue_spsc_locked.h:91
~iqueue_spsc_locked_base()
Destructor.
Definition queue_spsc_locked.h:178
static size_type get_next_index(size_type index, size_type maximum)
Calculate the next index.
Definition queue_spsc_locked.h:117
size_type read_index
Where to get the oldest data.
Definition queue_spsc_locked.h:130
size_type size_implementation() const
How many items in the queue?
Definition queue_spsc_locked.h:155
This is the base for all queue_spsc_locked that contain a particular type.
Definition queue_spsc_locked.h:193
bool emplace(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition queue_spsc_locked.h:391
bool emplace(const T1 &value1)
Definition queue_spsc_locked.h:343
bool pop_from_unlocked()
Definition queue_spsc_locked.h:430
bool emplace_from_unlocked(const T1 &value1)
Definition queue_spsc_locked.h:288
reference front_from_unlocked()
Definition queue_spsc_locked.h:453
bool emplace(const T1 &value1, const T2 &value2, const T3 &value3)
Definition queue_spsc_locked.h:375
bool emplace(const T1 &value1, const T2 &value2)
Definition queue_spsc_locked.h:359
bool emplace_from_unlocked(const T1 &value1, const T2 &value2)
Definition queue_spsc_locked.h:298
iqueue_spsc_locked(T *p_buffer_, size_type max_size_, const etl::ifunction< void > &lock_, const etl::ifunction< void > &unlock_)
The constructor that is called from derived classes.
Definition queue_spsc_locked.h:591
T & reference
A reference to the type used in the queue.
Definition queue_spsc_locked.h:201
bool pop()
Pop a value from the queue and discard.
Definition queue_spsc_locked.h:438
bool pop(reference value)
Pop a value from the queue.
Definition queue_spsc_locked.h:415
void clear()
Clear the queue.
Definition queue_spsc_locked.h:509
bool emplace_from_unlocked(const T1 &value1, const T2 &value2, const T3 &value3)
Definition queue_spsc_locked.h:308
reference front()
Peek a value from the front of the queue.
Definition queue_spsc_locked.h:470
T value_type
The type stored in the queue.
Definition queue_spsc_locked.h:200
const T & const_reference
A const reference to the type used in the queue.
Definition queue_spsc_locked.h:202
const_reference front_from_unlocked() const
Definition queue_spsc_locked.h:462
bool empty() const
Is the queue empty?
Definition queue_spsc_locked.h:575
size_type size() const
How many items in the queue?
Definition queue_spsc_locked.h:561
bool push_from_unlocked(const_reference value)
Push a value to the queue.
Definition queue_spsc_locked.h:211
bool emplace()
Definition queue_spsc_locked.h:327
base_t::size_type size_type
The type used for determining the size of the queue.
Definition queue_spsc_locked.h:206
bool emplace_from_unlocked(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition queue_spsc_locked.h:318
const_reference front() const
Peek a value from the front of the queue.
Definition queue_spsc_locked.h:484
bool full() const
Is the queue full?
Definition queue_spsc_locked.h:547
void clear_from_unlocked()
Clear the queue from the ISR.
Definition queue_spsc_locked.h:498
bool push(const_reference value)
Push a value to the queue.
Definition queue_spsc_locked.h:219
size_type available() const
How much free space available in the queue.
Definition queue_spsc_locked.h:533
bool pop_from_unlocked(reference value)
Definition queue_spsc_locked.h:407
Definition queue_spsc_locked.h:863
queue_spsc_locked(const etl::ifunction< void > &lock_, const etl::ifunction< void > &unlock_)
Default constructor.
Definition queue_spsc_locked.h:880
~queue_spsc_locked()
Destructor.
Definition queue_spsc_locked.h:889
Definition integral_limits.h:516
bitset_ext
Definition absolute.h:39
Definition memory_model.h:50