31#ifndef ETL_MPMC_QUEUE_MUTEX_INCLUDED
32#define ETL_MPMC_QUEUE_MUTEX_INCLUDED
51 template <
size_t MEMORY_MODEL = etl::memory_model::MEMORY_MODEL_LARGE>
52 class queue_mpmc_mutex_base
62 size_type capacity()
const
88 static size_type get_next_index(size_type index, size_type maximum)
92 if (index == maximum) ETL_UNLIKELY
100 size_type write_index;
101 size_type read_index;
102 size_type current_size;
103 const size_type MAX_SIZE;
108#if defined(ETL_POLYMORPHIC_MPMC_QUEUE_MUTEX) || defined(ETL_POLYMORPHIC_CONTAINERS)
132 template <
typename T, const
size_t MEMORY_MODEL = etl::memory_model::MEMORY_MODEL_LARGE>
133 class iqueue_mpmc_mutex :
public queue_mpmc_mutex_base<MEMORY_MODEL>
141 typedef T value_type;
142 typedef T& reference;
143 typedef const T& const_reference;
147 typedef typename base_t::size_type size_type;
149 using base_t::write_index;
150 using base_t::read_index;
151 using base_t::current_size;
152 using base_t::MAX_SIZE;
153 using base_t::get_next_index;
158 bool push(const_reference value)
162 bool result = push_implementation(value);
177 bool result = push_implementation(etl::move(value));
185#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_MPMC_MUTEX_FORCE_CPP03_IMPLEMENTATION)
190 template <
typename ...
Args>
210 bool result = emplace_implementation();
221 template <
typename T1>
222 bool emplace(
const T1& value1)
226 bool result = emplace_implementation(value1);
237 template <
typename T1,
typename T2>
238 bool emplace(
const T1& value1,
const T2& value2)
242 bool result = emplace_implementation(value1, value2);
253 template <
typename T1,
typename T2,
typename T3>
254 bool emplace(
const T1& value1,
const T2& value2,
const T3& value3)
258 bool result = emplace_implementation(value1, value2, value3);
269 template <
typename T1,
typename T2,
typename T3,
typename T4>
270 bool emplace(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
274 bool result = emplace_implementation(value1, value2, value3, value4);
285 bool pop(reference value)
289 bool result = pop_implementation(value);
303 bool result = pop_implementation();
317 reference result = front_implementation();
327 const_reference front()
const
331 const_reference result = front_implementation();
345 while (pop_implementation())
360 size_type result = (current_size == 0);
374 size_type result = (current_size == MAX_SIZE);
384 size_type
size()
const
388 size_type result = current_size;
398 size_type available()
const
402 size_type result = MAX_SIZE - current_size;
425 bool push_implementation(const_reference value)
427 if (current_size != MAX_SIZE)
429 ::new (&p_buffer[write_index])
T(value);
431 write_index = get_next_index(write_index, MAX_SIZE);
442#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_MPMC_MUTEX_FORCE_CPP03_IMPLEMENTATION)
448 if (current_size != MAX_SIZE)
450 ::new (&p_buffer[write_index])
T(etl::move(value));
452 write_index = get_next_index(write_index, MAX_SIZE);
464#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_MPMC_MUTEX_FORCE_CPP03_IMPLEMENTATION)
468 template <
typename ...
Args>
469 bool emplace_implementation(
Args&&...
args)
471 if (current_size != MAX_SIZE)
475 write_index = get_next_index(write_index, MAX_SIZE);
489 bool emplace_implementation()
491 if (current_size != MAX_SIZE)
493 ::new (&p_buffer[write_index])
T();
495 write_index = get_next_index(write_index, MAX_SIZE);
507 template <
typename T1>
508 bool emplace_implementation(
const T1& value1)
510 if (current_size != MAX_SIZE)
512 ::new (&p_buffer[write_index])
T(value1);
514 write_index = get_next_index(write_index, MAX_SIZE);
528 template <
typename T1,
typename T2>
529 bool emplace_implementation(
const T1& value1,
const T2& value2)
531 if (current_size != MAX_SIZE)
533 ::new (&p_buffer[write_index])
T(value1, value2);
535 write_index = get_next_index(write_index, MAX_SIZE);
549 template <
typename T1,
typename T2,
typename T3>
550 bool emplace_implementation(
const T1& value1,
const T2& value2,
const T3& value3)
552 if (current_size != MAX_SIZE)
554 ::new (&p_buffer[write_index])
T(value1, value2, value3);
556 write_index = get_next_index(write_index, MAX_SIZE);
570 template <
typename T1,
typename T2,
typename T3,
typename T4>
571 bool emplace_implementation(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
573 if (current_size != MAX_SIZE)
575 ::new (&p_buffer[write_index])
T(value1, value2, value3, value4);
577 write_index = get_next_index(write_index, MAX_SIZE);
592 bool pop_implementation(reference value)
594 if (current_size == 0)
600#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION)
601 value = etl::move(p_buffer[read_index]);
603 value = p_buffer[read_index];
606 p_buffer[read_index].~T();
608 read_index = get_next_index(read_index, MAX_SIZE);
618 bool pop_implementation()
620 if (current_size == 0)
626 p_buffer[read_index].~T();
628 read_index = get_next_index(read_index, MAX_SIZE);
638 reference front_implementation()
640 return p_buffer[read_index];
646 const_reference front_implementation()
const
648 return p_buffer[read_index];
668 template <
typename T,
size_t SIZE, const
size_t MEMORY_MODEL = etl::memory_model::MEMORY_MODEL_LARGE>
677 typedef typename base_t::size_type size_type;
681 static ETL_CONSTANT size_type MAX_SIZE = size_type(SIZE);
713 template <
typename T,
size_t SIZE, const
size_t MEMORY_MODEL>
714 ETL_CONSTANT
typename queue_mpmc_mutex<T, SIZE, MEMORY_MODEL>::size_type queue_mpmc_mutex<T, SIZE, MEMORY_MODEL>::MAX_SIZE;
This mutex class is implemented using CMSIS's RTOS2 mutexes.
Definition mutex_cmsis_os2.h:43
Definition alignment.h:231
Definition integral_limits.h:516
add_rvalue_reference
Definition type_traits_generator.h:1327
bitset_ext
Definition absolute.h:38
size_t max_size() const
Returns the maximum number of items in the variant_pool.
Definition variant_pool_generator.h:395
ETL_CONSTEXPR TContainer::size_type size(const TContainer &container)
Definition iterator.h:1187
pair holds two objects of arbitrary type
Definition utility.h:164
ETL_CONSTEXPR pair()
Default constructor.
Definition utility.h:176
Definition memory_model.h:50