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>
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>
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();
347 this->write_index = 0;
348 this->read_index = 0;
349 this->current_size = 0;
353 while (pop_implementation())
369 size_type result = (current_size == 0);
383 size_type result = (current_size == MAX_SIZE);
393 size_type
size()
const
397 size_type result = current_size;
407 size_type available()
const
411 size_type result = MAX_SIZE - current_size;
434 bool push_implementation(const_reference value)
436 if (current_size != MAX_SIZE)
438 ::new (&p_buffer[write_index])
T(value);
440 write_index = get_next_index(write_index, MAX_SIZE);
451#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_MPMC_MUTEX_FORCE_CPP03_IMPLEMENTATION)
457 if (current_size != MAX_SIZE)
459 ::new (&p_buffer[write_index])
T(etl::move(value));
461 write_index = get_next_index(write_index, MAX_SIZE);
473#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_MPMC_MUTEX_FORCE_CPP03_IMPLEMENTATION)
477 template <
typename ...
Args>
478 bool emplace_implementation(
Args&&...
args)
480 if (current_size != MAX_SIZE)
484 write_index = get_next_index(write_index, MAX_SIZE);
498 bool emplace_implementation()
500 if (current_size != MAX_SIZE)
502 ::new (&p_buffer[write_index])
T();
504 write_index = get_next_index(write_index, MAX_SIZE);
516 template <
typename T1>
517 bool emplace_implementation(
const T1& value1)
519 if (current_size != MAX_SIZE)
521 ::new (&p_buffer[write_index])
T(value1);
523 write_index = get_next_index(write_index, MAX_SIZE);
537 template <
typename T1,
typename T2>
538 bool emplace_implementation(
const T1& value1,
const T2& value2)
540 if (current_size != MAX_SIZE)
542 ::new (&p_buffer[write_index])
T(value1, value2);
544 write_index = get_next_index(write_index, MAX_SIZE);
558 template <
typename T1,
typename T2,
typename T3>
559 bool emplace_implementation(
const T1& value1,
const T2& value2,
const T3& value3)
561 if (current_size != MAX_SIZE)
563 ::new (&p_buffer[write_index])
T(value1, value2, value3);
565 write_index = get_next_index(write_index, MAX_SIZE);
579 template <
typename T1,
typename T2,
typename T3,
typename T4>
580 bool emplace_implementation(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
582 if (current_size != MAX_SIZE)
584 ::new (&p_buffer[write_index])
T(value1, value2, value3, value4);
586 write_index = get_next_index(write_index, MAX_SIZE);
601 bool pop_implementation(reference value)
603 if (current_size == 0)
609#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION)
610 value = etl::move(p_buffer[read_index]);
612 value = p_buffer[read_index];
615 p_buffer[read_index].~T();
617 read_index = get_next_index(read_index, MAX_SIZE);
627 bool pop_implementation()
629 if (current_size == 0)
635 p_buffer[read_index].~T();
637 read_index = get_next_index(read_index, MAX_SIZE);
647 reference front_implementation()
649 return p_buffer[read_index];
655 const_reference front_implementation()
const
657 return p_buffer[read_index];
677 template <
typename T,
size_t SIZE, const
size_t MEMORY_MODEL = etl::memory_model::MEMORY_MODEL_LARGE>
686 typedef typename base_t::size_type size_type;
690 static ETL_CONSTANT size_type MAX_SIZE = size_type(SIZE);
722 template <
typename T,
size_t SIZE, const
size_t MEMORY_MODEL>
723 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:245
Definition integral_limits.h:516
add_rvalue_reference
Definition type_traits_generator.h:1366
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
ETL_NODISCARD ETL_CONSTEXPR14 T round_half_even_unscaled(T value) ETL_NOEXCEPT
Definition scaled_rounding.h:314
Definition type_traits_generator.h:2190
Definition memory_model.h:50