31#ifndef ETL_SPSC_QUEUE_LOCKED_INCLUDED
32#define ETL_SPSC_QUEUE_LOCKED_INCLUDED
51 class queue_spsc_locked_exception :
public exception
55 queue_spsc_locked_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
56 :
exception(reason_, file_name_, line_number_)
65 class queue_spsc_locked_empty :
public queue_spsc_locked_exception
69 queue_spsc_locked_empty(string_type file_name_, numeric_type line_number_)
70 : queue_spsc_locked_exception(ETL_ERROR_TEXT(
"queue_spsc_locked:empty", ETL_QUEUE_SPSC_LOCKED_FILE_ID
"A"), file_name_, line_number_)
75 template <
size_t MEMORY_MODEL = etl::memory_model::MEMORY_MODEL_LARGE>
76 class iqueue_spsc_locked_base
137 , MAX_SIZE(max_size_)
148 if (index == maximum) ETL_UNLIKELY
198#if defined(ETL_POLYMORPHIC_SPSC_QUEUE_ISR) || defined(ETL_POLYMORPHIC_CONTAINERS)
220 template <
typename T, const
size_t MEMORY_MODEL = etl::memory_model::MEMORY_MODEL_LARGE>
225 typedef iqueue_spsc_locked_base<MEMORY_MODEL> base_t;
233 typedef T&& rvalue_reference;
242 return push_implementation(value);
252 bool result = push_implementation(value);
259#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION)
266 return push_implementation(etl::move(value));
273 bool push(rvalue_reference value)
277 bool result = push_implementation(etl::move(value));
285#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION)
290 template <
typename... Args>
293 return emplace_implementation(etl::forward<Args>(args)...);
300 template <
typename... Args>
305 bool result = emplace_implementation(etl::forward<Args>(args)...);
317 template <
typename T1>
320 return emplace_implementation(value1);
328 template <
typename T1,
typename T2>
331 return emplace_implementation(value1, value2);
339 template <
typename T1,
typename T2,
typename T3>
342 return emplace_implementation(value1, value2, value3);
350 template <
typename T1,
typename T2,
typename T3,
typename T4>
353 return emplace_implementation(value1, value2, value3, value4);
365 bool result = emplace_implementation();
377 template <
typename T1>
382 bool result = emplace_implementation(value1);
394 template <
typename T1,
typename T2>
395 bool emplace(
const T1& value1,
const T2& value2)
399 bool result = emplace_implementation(value1, value2);
411 template <
typename T1,
typename T2,
typename T3>
412 bool emplace(
const T1& value1,
const T2& value2,
const T3& value3)
416 bool result = emplace_implementation(value1, value2, value3);
428 template <
typename T1,
typename T2,
typename T3,
typename T4>
429 bool emplace(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
433 bool result = emplace_implementation(value1, value2, value3, value4);
447 return pop_implementation(value);
457 bool result = pop_implementation(value);
470 return pop_implementation();
480 bool result = pop_implementation();
493 return front_implementation();
502 return front_implementation();
512#if ETL_CHECKING_EXTRA
516 reference inner_result = front_implementation();
529 reference result = front_implementation();
541#if ETL_CHECKING_EXTRA
545 const_reference inner_result = front_implementation();
568 while (pop_implementation())
581 if ETL_IF_CONSTEXPR (etl::is_trivially_destructible<T>::value)
589 while (pop_implementation())
661 , p_buffer(p_buffer_)
689#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION)
694 bool push_implementation(rvalue_reference value)
698 ::new (&p_buffer[this->
write_index]) T(etl::move(value));
712#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION)
717 template <
typename... Args>
718 bool emplace_implementation(Args&&... args)
722 ::new (&p_buffer[this->
write_index]) T(etl::forward<Args>(args)...);
738 bool emplace_implementation()
758 template <
typename T1>
759 bool emplace_implementation(
const T1& value1)
779 template <
typename T1,
typename T2>
780 bool emplace_implementation(
const T1& value1,
const T2& value2)
784 ::new (&p_buffer[this->
write_index]) T(value1, value2);
800 template <
typename T1,
typename T2,
typename T3>
801 bool emplace_implementation(
const T1& value1,
const T2& value2,
const T3& value3)
805 ::new (&p_buffer[this->
write_index]) T(value1, value2, value3);
821 template <
typename T1,
typename T2,
typename T3,
typename T4>
822 bool emplace_implementation(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
826 ::new (&p_buffer[this->
write_index]) T(value1, value2, value3, value4);
852#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION)
853 value = etl::move(p_buffer[this->
read_index]);
889 bool pop_implementation()
917 const etl::ifunction<void>& lock;
918 const etl::ifunction<void>& unlock;
931 template <
typename T,
size_t SIZE, const
size_t MEMORY_MODEL = etl::memory_model::MEMORY_MODEL_LARGE>
944 static ETL_CONSTANT size_type MAX_SIZE =
size_type(SIZE);
951 : base_t(reinterpret_cast<T*>(buffer.raw), MAX_SIZE, lock_, unlock_)
977 template <
typename T,
size_t SIZE, const
size_t MEMORY_MODEL>
Definition queue_spsc_locked.h:77
size_type available_from_unlocked() const
How much free space available in the queue.
Definition queue_spsc_locked.h:86
const size_type MAX_SIZE
Definition queue_spsc_locked.h:159
bool empty_implementation() const
Is the queue empty?
Definition queue_spsc_locked.h:190
size_type available_implementation() const
How much free space available in the queue.
Definition queue_spsc_locked.h:166
bool full_from_unlocked() const
Is the queue full?
Definition queue_spsc_locked.h:94
bool empty_from_unlocked() const
Is the queue empty?
Definition queue_spsc_locked.h:110
size_type max_size() const
How many items can the queue hold.
Definition queue_spsc_locked.h:126
size_type size_from_unlocked() const
How many items in the queue?
Definition queue_spsc_locked.h:102
size_type current_size
The current size of the queue.
Definition queue_spsc_locked.h:158
size_type write_index
Where to input new data.
Definition queue_spsc_locked.h:156
bool full_implementation() const
Is the queue full?
Definition queue_spsc_locked.h:174
etl::size_type_lookup< MEMORY_MODEL >::type size_type
The type used for determining the size of queue.
Definition queue_spsc_locked.h:81
size_type capacity() const
How many items can the queue hold.
Definition queue_spsc_locked.h:118
~iqueue_spsc_locked_base()
Destructor.
Definition queue_spsc_locked.h:207
static size_type get_next_index(size_type index, size_type maximum)
Calculate the next index.
Definition queue_spsc_locked.h:144
size_type read_index
Where to get the oldest data.
Definition queue_spsc_locked.h:157
size_type size_implementation() const
How many items in the queue?
Definition queue_spsc_locked.h:182
This is the base for all queue_spsc_locked that contain a particular type.
Definition queue_spsc_locked.h:222
bool emplace(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition queue_spsc_locked.h:429
bool emplace(const T1 &value1)
Definition queue_spsc_locked.h:378
bool pop_from_unlocked()
Definition queue_spsc_locked.h:468
bool emplace_from_unlocked(const T1 &value1)
Definition queue_spsc_locked.h:318
reference front_from_unlocked()
Definition queue_spsc_locked.h:491
bool emplace(const T1 &value1, const T2 &value2, const T3 &value3)
Definition queue_spsc_locked.h:412
bool emplace(const T1 &value1, const T2 &value2)
Definition queue_spsc_locked.h:395
bool emplace_from_unlocked(const T1 &value1, const T2 &value2)
Definition queue_spsc_locked.h:329
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:659
T & reference
A reference to the type used in the queue.
Definition queue_spsc_locked.h:230
bool pop()
Pop a value from the queue and discard.
Definition queue_spsc_locked.h:476
bool pop(reference value)
Pop a value from the queue.
Definition queue_spsc_locked.h:453
void clear()
Clear the queue.
Definition queue_spsc_locked.h:577
bool emplace_from_unlocked(const T1 &value1, const T2 &value2, const T3 &value3)
Definition queue_spsc_locked.h:340
reference front()
Definition queue_spsc_locked.h:510
T value_type
The type stored in the queue.
Definition queue_spsc_locked.h:229
const T & const_reference
A const reference to the type used in the queue.
Definition queue_spsc_locked.h:231
const_reference front_from_unlocked() const
Definition queue_spsc_locked.h:500
bool empty() const
Is the queue empty?
Definition queue_spsc_locked.h:643
size_type size() const
How many items in the queue?
Definition queue_spsc_locked.h:629
bool push_from_unlocked(const_reference value)
Push a value to the queue.
Definition queue_spsc_locked.h:240
bool emplace()
Definition queue_spsc_locked.h:361
base_t::size_type size_type
The type used for determining the size of the queue.
Definition queue_spsc_locked.h:235
bool emplace_from_unlocked(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition queue_spsc_locked.h:351
const_reference front() const
Definition queue_spsc_locked.h:539
bool full() const
Is the queue full?
Definition queue_spsc_locked.h:615
void clear_from_unlocked()
Clear the queue from the ISR.
Definition queue_spsc_locked.h:566
bool push(const_reference value)
Push a value to the queue.
Definition queue_spsc_locked.h:248
size_type available() const
How much free space available in the queue.
Definition queue_spsc_locked.h:601
bool pop_from_unlocked(reference value)
Definition queue_spsc_locked.h:445
Definition queue_spsc_locked.h:933
queue_spsc_locked(const etl::ifunction< void > &lock_, const etl::ifunction< void > &unlock_)
Default constructor.
Definition queue_spsc_locked.h:950
~queue_spsc_locked()
Destructor.
Definition queue_spsc_locked.h:958
ETL_EXCEPTION_CONSTEXPR exception(string_type reason_, string_type, numeric_type)
Constructor.
Definition exception.h:81
Definition integral_limits.h:517
Definition queue_spsc_locked.h:66
Definition memory_model.h:50