31#ifndef ETL_QUEUE_LOCKABLE_INCLUDED
32#define ETL_QUEUE_LOCKABLE_INCLUDED
48 template <
size_t VMemory_Model = etl::memory_model::MEMORY_MODEL_LARGE>
49 class queue_lockable_base
69 return available_implementation();
79 size_type result = available_implementation();
92 return empty_implementation();
102 size_type result = empty_implementation();
115 return full_implementation();
125 size_type result = full_implementation();
138 return size_implementation();
148 size_type result = size_implementation();
188 if (index == maximum) ETL_UNLIKELY
200 virtual void unlock()
const = 0;
212 size_type available_implementation()
const
220 bool empty_implementation()
const
228 bool full_implementation()
const
248 template <
typename T, const
size_t VMemory_Model = etl::memory_model::MEMORY_MODEL_LARGE>
253 typedef queue_lockable_base<VMemory_Model> base_t;
261 typedef T&& rvalue_reference;
270 return push_implementation(value);
280 bool result = push_implementation(value);
287#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION)
293 return push_implementation(value);
299 bool push(rvalue_reference value)
303 bool result = push_implementation(etl::move(value));
311#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION)
315 template <
typename ... Args>
318 return emplace_implementation(etl::forward<Args>(args)...);
324 template <
typename ... Args>
329 bool result = emplace_implementation(etl::forward<Args>(args)...);
339 template <
typename T1>
342 return emplace_implementation(value1);
348 template <
typename T1,
typename T2>
351 return emplace_implementation(value1, value2);
357 template <
typename T1,
typename T2,
typename T3>
360 return emplace_implementation(value1, value2, value3);
366 template <
typename T1,
typename T2,
typename T3,
typename T4>
367 bool emplace_unlocked(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
369 return emplace_implementation(value1, value2, value3, value4);
379 bool result = emplace_implementation();
389 template <
typename T1>
394 bool result = emplace_implementation(value1);
404 template <
typename T1,
typename T2>
405 bool emplace(
const T1& value1,
const T2& value2)
409 bool result = emplace_implementation(value1, value2);
419 template <
typename T1,
typename T2,
typename T3>
420 bool emplace(
const T1& value1,
const T2& value2,
const T3& value3)
424 bool result = emplace_implementation(value1, value2, value3);
434 template <
typename T1,
typename T2,
typename T3,
typename T4>
435 bool emplace(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
439 bool result = emplace_implementation(value1, value2, value3, value4);
452 return pop_implementation();
463 bool result = pop_implementation();
475 return pop_implementation(value);
485 bool result = pop_implementation(value);
497 return front_implementation();
505 return front_implementation();
515 reference result = front_implementation();
529 const_reference result = front_implementation();
541 while (pop_implementation())
554 if ETL_IF_CONSTEXPR(etl::is_trivially_destructible<T>::value)
556 this->write_index = 0;
557 this->read_index = 0;
558 this->current_size = 0;
562 while (pop_implementation())
578 , p_buffer(p_buffer_)
589 if (this->current_size != this->Max_Size)
591 ::new (&p_buffer[this->write_index]) T(value);
593 this->write_index = this->
get_next_index(this->write_index, this->Max_Size);
595 ++this->current_size;
604#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION)
608 bool push_implementation(rvalue_reference value)
612 ::new (&p_buffer[this->
write_index]) T(etl::move(value));
626#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION)
630 template <
typename ... Args>
631 bool emplace_implementation(Args&&... args)
635 ::new (&p_buffer[this->
write_index]) T(etl::forward<Args>(args)...);
651 template <
typename T1>
652 bool emplace_implementation(
const T1& value1)
672 template <
typename T1,
typename T2>
673 bool emplace_implementation(
const T1& value1,
const T2& value2)
677 ::new (&p_buffer[this->
write_index]) T(value1, value2);
693 template <
typename T1,
typename T2,
typename T3>
694 bool emplace_implementation(
const T1& value1,
const T2& value2,
const T3& value3)
698 ::new (&p_buffer[this->
write_index]) T(value1, value2, value3);
714 template <
typename T1,
typename T2,
typename T3,
typename T4>
715 bool emplace_implementation(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
719 ::new (&p_buffer[this->
write_index]) T(value1, value2, value3, value4);
736 bool pop_implementation()
764#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION)
765 value = etl::move(p_buffer[this->
read_index]);
814 template <
typename T,
size_t VSize,
size_t VMemory_Model = etl::memory_model::MEMORY_MODEL_LARGE>
827 static ETL_CONSTANT size_type Max_Size =
size_type(VSize);
828 static ETL_CONSTANT size_type Memory_Model =
size_type(VMemory_Model);
835 : base_t(reinterpret_cast<T*>(buffer.raw), Max_Size)
864 template <
typename T,
size_t VSize,
size_t VMemory_Model>
867 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:250
bool pop(reference value)
Pop a value from the queue.
Definition queue_lockable.h:481
reference front_unlocked()
Peek a value at the front of the queue without locking.
Definition queue_lockable.h:495
bool pop_unlocked(reference value)
Pop a value from the queue without locking.
Definition queue_lockable.h:473
bool pop()
Pop a value from the queue and discard.
Definition queue_lockable.h:459
reference front()
Peek a value at the front of the queue.
Definition queue_lockable.h:511
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:435
bool emplace(const T1 &value1)
Constructs a value in the queue 'in place'.
Definition queue_lockable.h:390
void clear()
Clear the queue.
Definition queue_lockable.h:550
bool emplace_unlocked(const T1 &value1, const T2 &value2, const T3 &value3)
Constructs a value in the queue 'in place'.
Definition queue_lockable.h:358
const_reference front_unlocked() const
Peek a value at the front of the queue without locking.
Definition queue_lockable.h:503
bool emplace_unlocked(const T1 &value1)
Constructs a value in the queue 'in place'.
Definition queue_lockable.h:340
bool push_unlocked(const_reference value)
Push a value to the queue without locking.
Definition queue_lockable.h:268
bool pop_unlocked()
Pop a value from the queue without locking, and discard.
Definition queue_lockable.h:450
bool emplace(const T1 &value1, const T2 &value2, const T3 &value3)
Constructs a value in the queue 'in place'.
Definition queue_lockable.h:420
bool emplace_unlocked(const T1 &value1, const T2 &value2)
Constructs a value in the queue 'in place'.
Definition queue_lockable.h:349
iqueue_lockable(T *p_buffer_, size_type max_size_)
The constructor that is called from derived classes.
Definition queue_lockable.h:576
bool emplace(const T1 &value1, const T2 &value2)
Constructs a value in the queue 'in place'.
Definition queue_lockable.h:405
base_t::size_type size_type
The type used for determining the size of the queue.
Definition queue_lockable.h:263
const_reference front() const
Peek a value at the front of the queue.
Definition queue_lockable.h:525
bool emplace()
Constructs a value in the queue 'in place'.
Definition queue_lockable.h:375
const T & const_reference
A const reference to the type used in the queue.
Definition queue_lockable.h:259
T value_type
The type stored in the queue.
Definition queue_lockable.h:257
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:367
bool push(const_reference value)
Push a value to the queue.
Definition queue_lockable.h:276
void clear_unlocked()
Clear the queue, unlocked.
Definition queue_lockable.h:539
T & reference
A reference to the type used in the queue.
Definition queue_lockable.h:258
Definition queue_lockable.h:50
size_type size_unlocked() const
Definition queue_lockable.h:136
size_type capacity() const
How many items can the queue hold.
Definition queue_lockable.h:158
size_type max_size() const
How many items can the queue hold.
Definition queue_lockable.h:166
bool empty() const
Is the queue empty?
Definition queue_lockable.h:98
bool empty_unlocked() const
Definition queue_lockable.h:90
const size_type Max_Size
Definition queue_lockable.h:205
size_type read_index
Where to get the oldest data.
Definition queue_lockable.h:203
size_type current_size
The current size of the queue.
Definition queue_lockable.h:204
size_type available_unlocked() const
Definition queue_lockable.h:67
etl::size_type_lookup< VMemory_Model >::type size_type
The type used for determining the size of queue.
Definition queue_lockable.h:54
size_type write_index
Where to input new data.
Definition queue_lockable.h:202
static size_type get_next_index(size_type index, size_type maximum)
Calculate the next index.
Definition queue_lockable.h:184
size_type size() const
How many items in the queue?
Definition queue_lockable.h:144
virtual void lock() const =0
The pure virtual lock and unlock functions.
bool full_unlocked() const
Definition queue_lockable.h:113
size_type available() const
How much free space available in the queue.
Definition queue_lockable.h:75
bool full() const
Is the queue full?
Definition queue_lockable.h:121
virtual ~queue_lockable_base()
Destructor.
Definition queue_lockable.h:59
Definition queue_lockable.h:816
~queue_lockable()
Destructor.
Definition queue_lockable.h:842
queue_lockable()
Default constructor.
Definition queue_lockable.h:834
Definition integral_limits.h:516
bitset_ext
Definition absolute.h:39
Definition memory_model.h:50