31#ifndef ETL_QUEUE_LOCKABLE_INCLUDED
32#define ETL_QUEUE_LOCKABLE_INCLUDED
57 queue_lockable_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
58 :
exception(reason_, file_name_, line_number_)
67 class queue_lockable_empty :
public queue_lockable_exception
71 queue_lockable_empty(string_type file_name_, numeric_type line_number_)
72 : queue_lockable_exception(ETL_ERROR_TEXT(
"queue_lockable:empty", ETL_QUEUE_SPSC_LOCKABLE_FILE_ID
"A"), file_name_, line_number_)
77 template <
size_t VMemory_Model = etl::memory_model::MEMORY_MODEL_LARGE>
78 class queue_lockable_base
96 return available_implementation();
106 size_type result = available_implementation();
119 return empty_implementation();
129 size_type result = empty_implementation();
142 return full_implementation();
152 size_type result = full_implementation();
165 return size_implementation();
175 size_type result = size_implementation();
204 , Max_Size(max_size_)
215 if (index == maximum) ETL_UNLIKELY
227 virtual void unlock()
const = 0;
239 size_type available_implementation()
const
247 bool empty_implementation()
const
255 bool full_implementation()
const
276 template <
typename T, const
size_t VMemory_Model = etl::memory_model::MEMORY_MODEL_LARGE>
281 typedef queue_lockable_base<VMemory_Model> base_t;
289 typedef T&& rvalue_reference;
298 return push_implementation(value);
308 bool result = push_implementation(value);
315#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION)
321 return push_implementation(value);
327 bool push(rvalue_reference value)
331 bool result = push_implementation(etl::move(value));
339#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION)
343 template <
typename... Args>
346 return emplace_implementation(etl::forward<Args>(args)...);
352 template <
typename... Args>
357 bool result = emplace_implementation(etl::forward<Args>(args)...);
367 template <
typename T1>
370 return emplace_implementation(value1);
376 template <
typename T1,
typename T2>
379 return emplace_implementation(value1, value2);
385 template <
typename T1,
typename T2,
typename T3>
388 return emplace_implementation(value1, value2, value3);
394 template <
typename T1,
typename T2,
typename T3,
typename T4>
395 bool emplace_unlocked(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
397 return emplace_implementation(value1, value2, value3, value4);
407 bool result = emplace_implementation();
417 template <
typename T1>
422 bool result = emplace_implementation(value1);
432 template <
typename T1,
typename T2>
433 bool emplace(
const T1& value1,
const T2& value2)
437 bool result = emplace_implementation(value1, value2);
447 template <
typename T1,
typename T2,
typename T3>
448 bool emplace(
const T1& value1,
const T2& value2,
const T3& value3)
452 bool result = emplace_implementation(value1, value2, value3);
462 template <
typename T1,
typename T2,
typename T3,
typename T4>
463 bool emplace(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
467 bool result = emplace_implementation(value1, value2, value3, value4);
480 return pop_implementation();
490 bool result = pop_implementation();
502 return pop_implementation(value);
512 bool result = pop_implementation(value);
527 return front_implementation();
538 return front_implementation();
548#if ETL_CHECKING_EXTRA
552 reference inner_result = front_implementation();
565 reference result = front_implementation();
577#if ETL_CHECKING_EXTRA
581 const_reference inner_result = front_implementation();
594 const_reference result = front_implementation();
604 while (pop_implementation())
617 if ETL_IF_CONSTEXPR (etl::is_trivially_destructible<T>::value)
619 this->write_index = 0;
620 this->read_index = 0;
621 this->current_size = 0;
625 while (pop_implementation())
641 , p_buffer(p_buffer_)
652 if (this->current_size != this->Max_Size)
654 ::new (&p_buffer[this->write_index]) T(value);
656 this->write_index = this->
get_next_index(this->write_index, this->Max_Size);
658 ++this->current_size;
667#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION)
671 bool push_implementation(rvalue_reference value)
675 ::new (&p_buffer[this->
write_index]) T(etl::move(value));
689#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION)
693 template <
typename... Args>
694 bool emplace_implementation(Args&&... args)
698 ::new (&p_buffer[this->
write_index]) T(etl::forward<Args>(args)...);
714 template <
typename T1>
715 bool emplace_implementation(
const T1& value1)
735 template <
typename T1,
typename T2>
736 bool emplace_implementation(
const T1& value1,
const T2& value2)
740 ::new (&p_buffer[this->
write_index]) T(value1, value2);
756 template <
typename T1,
typename T2,
typename T3>
757 bool emplace_implementation(
const T1& value1,
const T2& value2,
const T3& value3)
761 ::new (&p_buffer[this->
write_index]) T(value1, value2, value3);
777 template <
typename T1,
typename T2,
typename T3,
typename T4>
778 bool emplace_implementation(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
782 ::new (&p_buffer[this->
write_index]) T(value1, value2, value3, value4);
799 bool pop_implementation()
827#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION)
828 value = etl::move(p_buffer[this->
read_index]);
878 template <
typename T,
size_t VSize,
size_t VMemory_Model = etl::memory_model::MEMORY_MODEL_LARGE>
891 static ETL_CONSTANT size_type Max_Size =
size_type(VSize);
892 static ETL_CONSTANT size_type Memory_Model =
size_type(VMemory_Model);
899 : base_t(reinterpret_cast<T*>(buffer.raw), Max_Size)
928 template <
typename T,
size_t VSize,
size_t VMemory_Model>
931 template <
typename T,
size_t VSize,
size_t VMemory_Model>
This is the base for all queues that contain a particular type.
Definition queue_lockable.h:278
bool pop(reference value)
Pop a value from the queue.
Definition queue_lockable.h:508
reference front_unlocked()
Definition queue_lockable.h:524
bool pop_unlocked(reference value)
Pop a value from the queue without locking.
Definition queue_lockable.h:500
bool pop()
Pop a value from the queue and discard.
Definition queue_lockable.h:486
reference front()
Definition queue_lockable.h:546
bool emplace(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Constructs a value in the queue 'in place'.
Definition queue_lockable.h:463
bool emplace(const T1 &value1)
Constructs a value in the queue 'in place'.
Definition queue_lockable.h:418
void clear()
Clear the queue.
Definition queue_lockable.h:613
bool emplace_unlocked(const T1 &value1, const T2 &value2, const T3 &value3)
Constructs a value in the queue 'in place'.
Definition queue_lockable.h:386
const_reference front_unlocked() const
Definition queue_lockable.h:535
bool emplace_unlocked(const T1 &value1)
Constructs a value in the queue 'in place'.
Definition queue_lockable.h:368
bool push_unlocked(const_reference value)
Push a value to the queue without locking.
Definition queue_lockable.h:296
bool pop_unlocked()
Pop a value from the queue without locking, and discard.
Definition queue_lockable.h:478
bool emplace(const T1 &value1, const T2 &value2, const T3 &value3)
Constructs a value in the queue 'in place'.
Definition queue_lockable.h:448
bool emplace_unlocked(const T1 &value1, const T2 &value2)
Constructs a value in the queue 'in place'.
Definition queue_lockable.h:377
iqueue_lockable(T *p_buffer_, size_type max_size_)
The constructor that is called from derived classes.
Definition queue_lockable.h:639
bool emplace(const T1 &value1, const T2 &value2)
Constructs a value in the queue 'in place'.
Definition queue_lockable.h:433
base_t::size_type size_type
The type used for determining the size of the queue.
Definition queue_lockable.h:291
const_reference front() const
Definition queue_lockable.h:575
bool emplace()
Constructs a value in the queue 'in place'.
Definition queue_lockable.h:403
const T & const_reference
A const reference to the type used in the queue.
Definition queue_lockable.h:287
T value_type
The type stored in the queue.
Definition queue_lockable.h:285
bool emplace_unlocked(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Constructs a value in the queue 'in place'.
Definition queue_lockable.h:395
bool push(const_reference value)
Push a value to the queue.
Definition queue_lockable.h:304
void clear_unlocked()
Clear the queue, unlocked.
Definition queue_lockable.h:602
T & reference
A reference to the type used in the queue.
Definition queue_lockable.h:286
Definition queue_lockable.h:79
size_type size_unlocked() const
Definition queue_lockable.h:163
size_type capacity() const
How many items can the queue hold.
Definition queue_lockable.h:185
size_type max_size() const
How many items can the queue hold.
Definition queue_lockable.h:193
bool empty() const
Is the queue empty?
Definition queue_lockable.h:125
bool empty_unlocked() const
Definition queue_lockable.h:117
const size_type Max_Size
Definition queue_lockable.h:232
size_type read_index
Where to get the oldest data.
Definition queue_lockable.h:230
size_type current_size
The current size of the queue.
Definition queue_lockable.h:231
size_type available_unlocked() const
Definition queue_lockable.h:94
etl::size_type_lookup< VMemory_Model >::type size_type
The type used for determining the size of queue.
Definition queue_lockable.h:83
size_type write_index
Where to input new data.
Definition queue_lockable.h:229
static size_type get_next_index(size_type index, size_type maximum)
Calculate the next index.
Definition queue_lockable.h:211
size_type size() const
How many items in the queue?
Definition queue_lockable.h:171
virtual void lock() const =0
The pure virtual lock and unlock functions.
bool full_unlocked() const
Definition queue_lockable.h:140
size_type available() const
How much free space available in the queue.
Definition queue_lockable.h:102
bool full() const
Is the queue full?
Definition queue_lockable.h:148
virtual ~queue_lockable_base()
Destructor.
Definition queue_lockable.h:88
Definition queue_lockable.h:880
~queue_lockable()
Destructor.
Definition queue_lockable.h:906
queue_lockable()
Default constructor.
Definition queue_lockable.h:898
ETL_EXCEPTION_CONSTEXPR exception(string_type reason_, string_type, numeric_type)
Constructor.
Definition exception.h:81
Definition integral_limits.h:518
Definition queue_lockable.h:68
bitset_ext
Definition absolute.h:40
Definition memory_model.h:50