31#ifndef ETL_SPSC_QUEUE_LOCKED_INCLUDED
32#define ETL_SPSC_QUEUE_LOCKED_INCLUDED
53 class queue_spsc_locked_exception :
public exception
57 queue_spsc_locked_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
58 :
exception(reason_, file_name_, line_number_)
67 class queue_spsc_locked_empty :
public queue_spsc_locked_exception
71 queue_spsc_locked_empty(string_type file_name_, numeric_type line_number_)
72 : queue_spsc_locked_exception(ETL_ERROR_TEXT(
"queue_spsc_locked:empty", ETL_QUEUE_SPSC_LOCKED_FILE_ID
"A"), file_name_, line_number_)
77 template <
size_t MEMORY_MODEL = etl::memory_model::MEMORY_MODEL_LARGE>
78 class iqueue_spsc_locked_base
139 , MAX_SIZE(max_size_)
150 if (index == maximum) ETL_UNLIKELY
200#if defined(ETL_POLYMORPHIC_SPSC_QUEUE_ISR) || defined(ETL_POLYMORPHIC_CONTAINERS)
222 template <
typename T, const
size_t MEMORY_MODEL = etl::memory_model::MEMORY_MODEL_LARGE>
227 typedef iqueue_spsc_locked_base<MEMORY_MODEL> base_t;
235 typedef T&& rvalue_reference;
244 return push_implementation(value);
254 bool result = push_implementation(value);
261#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION)
268 return push_implementation(etl::move(value));
275 bool push(rvalue_reference value)
279 bool result = push_implementation(etl::move(value));
287#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION)
292 template <
typename... Args>
295 return emplace_implementation(etl::forward<Args>(args)...);
302 template <
typename... Args>
307 bool result = emplace_implementation(etl::forward<Args>(args)...);
319 template <
typename T1>
322 return emplace_implementation(value1);
330 template <
typename T1,
typename T2>
333 return emplace_implementation(value1, value2);
341 template <
typename T1,
typename T2,
typename T3>
344 return emplace_implementation(value1, value2, value3);
352 template <
typename T1,
typename T2,
typename T3,
typename T4>
355 return emplace_implementation(value1, value2, value3, value4);
367 bool result = emplace_implementation();
379 template <
typename T1>
384 bool result = emplace_implementation(value1);
396 template <
typename T1,
typename T2>
397 bool emplace(
const T1& value1,
const T2& value2)
401 bool result = emplace_implementation(value1, value2);
413 template <
typename T1,
typename T2,
typename T3>
414 bool emplace(
const T1& value1,
const T2& value2,
const T3& value3)
418 bool result = emplace_implementation(value1, value2, value3);
430 template <
typename T1,
typename T2,
typename T3,
typename T4>
431 bool emplace(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
435 bool result = emplace_implementation(value1, value2, value3, value4);
449 return pop_implementation(value);
459 bool result = pop_implementation(value);
472 return pop_implementation();
482 bool result = pop_implementation();
495 return front_implementation();
504 return front_implementation();
514#if ETL_CHECKING_EXTRA
518 reference inner_result = front_implementation();
531 reference result = front_implementation();
543#if ETL_CHECKING_EXTRA
547 const_reference inner_result = front_implementation();
570 while (pop_implementation())
583 if ETL_IF_CONSTEXPR (etl::is_trivially_destructible<T>::value)
591 while (pop_implementation())
663 , p_buffer(p_buffer_)
691#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION)
696 bool push_implementation(rvalue_reference value)
700 ::new (&p_buffer[this->
write_index]) T(etl::move(value));
714#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION)
719 template <
typename... Args>
720 bool emplace_implementation(Args&&... args)
724 ::new (&p_buffer[this->
write_index]) T(etl::forward<Args>(args)...);
740 bool emplace_implementation()
760 template <
typename T1>
761 bool emplace_implementation(
const T1& value1)
781 template <
typename T1,
typename T2>
782 bool emplace_implementation(
const T1& value1,
const T2& value2)
786 ::new (&p_buffer[this->
write_index]) T(value1, value2);
802 template <
typename T1,
typename T2,
typename T3>
803 bool emplace_implementation(
const T1& value1,
const T2& value2,
const T3& value3)
807 ::new (&p_buffer[this->
write_index]) T(value1, value2, value3);
823 template <
typename T1,
typename T2,
typename T3,
typename T4>
824 bool emplace_implementation(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
828 ::new (&p_buffer[this->
write_index]) T(value1, value2, value3, value4);
854#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION)
855 value = etl::move(p_buffer[this->
read_index]);
891 bool pop_implementation()
919 const etl::ifunction<void>& lock;
920 const etl::ifunction<void>& unlock;
933 template <
typename T,
size_t SIZE, const
size_t MEMORY_MODEL = etl::memory_model::MEMORY_MODEL_LARGE>
946 static ETL_CONSTANT size_type MAX_SIZE =
size_type(SIZE);
953 : base_t(reinterpret_cast<T*>(buffer.raw), MAX_SIZE, lock_, unlock_)
979 template <
typename T,
size_t SIZE, const
size_t MEMORY_MODEL>
Definition queue_spsc_locked.h:79
size_type available_from_unlocked() const
How much free space available in the queue.
Definition queue_spsc_locked.h:88
const size_type MAX_SIZE
Definition queue_spsc_locked.h:161
bool empty_implementation() const
Is the queue empty?
Definition queue_spsc_locked.h:192
size_type available_implementation() const
How much free space available in the queue.
Definition queue_spsc_locked.h:168
bool full_from_unlocked() const
Is the queue full?
Definition queue_spsc_locked.h:96
bool empty_from_unlocked() const
Is the queue empty?
Definition queue_spsc_locked.h:112
size_type max_size() const
How many items can the queue hold.
Definition queue_spsc_locked.h:128
size_type size_from_unlocked() const
How many items in the queue?
Definition queue_spsc_locked.h:104
size_type current_size
The current size of the queue.
Definition queue_spsc_locked.h:160
size_type write_index
Where to input new data.
Definition queue_spsc_locked.h:158
bool full_implementation() const
Is the queue full?
Definition queue_spsc_locked.h:176
etl::size_type_lookup< MEMORY_MODEL >::type size_type
The type used for determining the size of queue.
Definition queue_spsc_locked.h:83
size_type capacity() const
How many items can the queue hold.
Definition queue_spsc_locked.h:120
~iqueue_spsc_locked_base()
Destructor.
Definition queue_spsc_locked.h:209
static size_type get_next_index(size_type index, size_type maximum)
Calculate the next index.
Definition queue_spsc_locked.h:146
size_type read_index
Where to get the oldest data.
Definition queue_spsc_locked.h:159
size_type size_implementation() const
How many items in the queue?
Definition queue_spsc_locked.h:184
This is the base for all queue_spsc_locked that contain a particular type.
Definition queue_spsc_locked.h:224
bool emplace(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition queue_spsc_locked.h:431
bool emplace(const T1 &value1)
Definition queue_spsc_locked.h:380
bool pop_from_unlocked()
Definition queue_spsc_locked.h:470
bool emplace_from_unlocked(const T1 &value1)
Definition queue_spsc_locked.h:320
reference front_from_unlocked()
Definition queue_spsc_locked.h:493
bool emplace(const T1 &value1, const T2 &value2, const T3 &value3)
Definition queue_spsc_locked.h:414
bool emplace(const T1 &value1, const T2 &value2)
Definition queue_spsc_locked.h:397
bool emplace_from_unlocked(const T1 &value1, const T2 &value2)
Definition queue_spsc_locked.h:331
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:661
T & reference
A reference to the type used in the queue.
Definition queue_spsc_locked.h:232
bool pop()
Pop a value from the queue and discard.
Definition queue_spsc_locked.h:478
bool pop(reference value)
Pop a value from the queue.
Definition queue_spsc_locked.h:455
void clear()
Clear the queue.
Definition queue_spsc_locked.h:579
bool emplace_from_unlocked(const T1 &value1, const T2 &value2, const T3 &value3)
Definition queue_spsc_locked.h:342
reference front()
Definition queue_spsc_locked.h:512
T value_type
The type stored in the queue.
Definition queue_spsc_locked.h:231
const T & const_reference
A const reference to the type used in the queue.
Definition queue_spsc_locked.h:233
const_reference front_from_unlocked() const
Definition queue_spsc_locked.h:502
bool empty() const
Is the queue empty?
Definition queue_spsc_locked.h:645
size_type size() const
How many items in the queue?
Definition queue_spsc_locked.h:631
bool push_from_unlocked(const_reference value)
Push a value to the queue.
Definition queue_spsc_locked.h:242
bool emplace()
Definition queue_spsc_locked.h:363
base_t::size_type size_type
The type used for determining the size of the queue.
Definition queue_spsc_locked.h:237
bool emplace_from_unlocked(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition queue_spsc_locked.h:353
const_reference front() const
Definition queue_spsc_locked.h:541
bool full() const
Is the queue full?
Definition queue_spsc_locked.h:617
void clear_from_unlocked()
Clear the queue from the ISR.
Definition queue_spsc_locked.h:568
bool push(const_reference value)
Push a value to the queue.
Definition queue_spsc_locked.h:250
size_type available() const
How much free space available in the queue.
Definition queue_spsc_locked.h:603
bool pop_from_unlocked(reference value)
Definition queue_spsc_locked.h:447
Definition queue_spsc_locked.h:935
queue_spsc_locked(const etl::ifunction< void > &lock_, const etl::ifunction< void > &unlock_)
Default constructor.
Definition queue_spsc_locked.h:952
~queue_spsc_locked()
Destructor.
Definition queue_spsc_locked.h:960
ETL_EXCEPTION_CONSTEXPR exception(string_type reason_, string_type, numeric_type)
Constructor.
Definition exception.h:81
Definition integral_limits.h:518
Definition queue_spsc_locked.h:68
bitset_ext
Definition absolute.h:40
Definition memory_model.h:50