distortos
v0.7.0
object-oriented C++ RTOS for microcontrollers
|
MessageQueue class is a message queue for thread-thread, thread-interrupt or interrupt-interrupt communication. It supports multiple readers and multiple writers. It is implemented as a wrapper for internal::MessageQueueBase. More...
#include "distortos/MessageQueue.hpp"
Public Types | |
using | EntryStorage = internal::MessageQueueBase::EntryStorage |
type of uninitialized storage for Entry with link More... | |
using | ValueStorage = internal::MessageQueueBase::ValueStorage< T > |
type of uninitialized storage for value More... | |
using | ValueType = T |
type of data in queue More... | |
using | EntryStorageUniquePointer = internal::MessageQueueBase::EntryStorageUniquePointer |
import EntryStorageUniquePointer type from internal::MessageQueueBase class More... | |
using | ValueStorageUniquePointer = std::unique_ptr< ValueStorage[], internal::MessageQueueBase::ValueStorageUniquePointer::deleter_type > |
unique_ptr (with deleter) to ValueStorage[] More... | |
Public Member Functions | |
MessageQueue (EntryStorageUniquePointer &&entryStorageUniquePointer, ValueStorageUniquePointer &&valueStorageUniquePointer, const size_t maxElements) | |
MessageQueue's constructor. More... | |
~MessageQueue () | |
MessageQueue's destructor. More... | |
template<typename... Args> | |
int | emplace (const uint8_t priority, Args &&... args) |
Emplaces the element in the queue. More... | |
size_t | getCapacity () const |
int | pop (uint8_t &priority, T &value) |
Pops oldest element with highest priority from the queue. More... | |
int | push (const uint8_t priority, const T &value) |
Pushes the element to the queue. More... | |
int | push (const uint8_t priority, T &&value) |
Pushes the element to the queue. More... | |
template<typename... Args> | |
int | tryEmplace (const uint8_t priority, Args &&... args) |
Tries to emplace the element in the queue. More... | |
template<typename... Args> | |
int | tryEmplaceFor (const TickClock::duration duration, const uint8_t priority, Args &&... args) |
Tries to emplace the element in the queue for a given duration of time. More... | |
template<typename Rep , typename Period , typename... Args> | |
int | tryEmplaceFor (const std::chrono::duration< Rep, Period > duration, const uint8_t priority, Args &&... args) |
Tries to emplace the element in the queue for a given duration of time. More... | |
template<typename... Args> | |
int | tryEmplaceUntil (const TickClock::time_point timePoint, const uint8_t priority, Args &&... args) |
Tries to emplace the element in the queue until a given time point. More... | |
template<typename Duration , typename... Args> | |
int | tryEmplaceUntil (const std::chrono::time_point< TickClock, Duration > timePoint, const uint8_t priority, Args &&... args) |
Tries to emplace the element in the queue until a given time point. More... | |
int | tryPop (uint8_t &priority, T &value) |
Tries to pop oldest element with highest priority from the queue. More... | |
int | tryPopFor (const TickClock::duration duration, uint8_t &priority, T &value) |
Tries to pop oldest element with highest priority from the queue for a given duration of time. More... | |
template<typename Rep , typename Period > | |
int | tryPopFor (const std::chrono::duration< Rep, Period > duration, uint8_t &priority, T &value) |
Tries to pop oldest element with highest priority from the queue for a given duration of time. More... | |
int | tryPopUntil (const TickClock::time_point timePoint, uint8_t &priority, T &value) |
Tries to pop oldest element with highest priority from the queue until a given time point. More... | |
template<typename Duration > | |
int | tryPopUntil (const std::chrono::time_point< TickClock, Duration > timePoint, uint8_t &priority, T &value) |
Tries to pop oldest element with highest priority from the queue until a given time point. More... | |
int | tryPush (const uint8_t priority, const T &value) |
Tries to push the element to the queue. More... | |
int | tryPush (const uint8_t priority, T &&value) |
Tries to push the element to the queue. More... | |
int | tryPushFor (const TickClock::duration duration, const uint8_t priority, const T &value) |
Tries to push the element to the queue for a given duration of time. More... | |
template<typename Rep , typename Period > | |
int | tryPushFor (const std::chrono::duration< Rep, Period > duration, const uint8_t priority, const T &value) |
Tries to push the element to the queue for a given duration of time. More... | |
int | tryPushFor (const TickClock::duration duration, const uint8_t priority, T &&value) |
Tries to push the element to the queue for a given duration of time. More... | |
template<typename Rep , typename Period > | |
int | tryPushFor (const std::chrono::duration< Rep, Period > duration, const uint8_t priority, T &&value) |
Tries to push the element to the queue for a given duration of time. More... | |
int | tryPushUntil (const TickClock::time_point timePoint, const uint8_t priority, const T &value) |
Tries to push the element to the queue until a given time point. More... | |
template<typename Duration > | |
int | tryPushUntil (const std::chrono::time_point< TickClock, Duration > timePoint, const uint8_t priority, const T &value) |
Tries to push the element to the queue until a given time point. More... | |
int | tryPushUntil (const TickClock::time_point timePoint, const uint8_t priority, T &&value) |
Tries to push the element to the queue until a given time point. More... | |
template<typename Duration > | |
int | tryPushUntil (const std::chrono::time_point< TickClock, Duration > timePoint, const uint8_t priority, T &&value) |
Tries to push the element to the queue until a given time point. More... | |
Private Member Functions | |
template<typename... Args> | |
int | emplaceInternal (const internal::SemaphoreFunctor &waitSemaphoreFunctor, uint8_t priority, Args &&... args) |
Emplaces the element in the queue. More... | |
int | popInternal (const internal::SemaphoreFunctor &waitSemaphoreFunctor, uint8_t &priority, T &value) |
Pops oldest element with highest priority from the queue. More... | |
int | pushInternal (const internal::SemaphoreFunctor &waitSemaphoreFunctor, uint8_t priority, const T &value) |
Pushes the element to the queue. More... | |
int | pushInternal (const internal::SemaphoreFunctor &waitSemaphoreFunctor, uint8_t priority, T &&value) |
Pushes the element to the queue. More... | |
Private Attributes | |
internal::MessageQueueBase | messageQueueBase_ |
contained internal::MessageQueueBase object which implements whole functionality More... | |
MessageQueue class is a message queue for thread-thread, thread-interrupt or interrupt-interrupt communication. It supports multiple readers and multiple writers. It is implemented as a wrapper for internal::MessageQueueBase.
Similar to POSIX mqd_t - http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/mqueue.h.html
T | is the type of data in queue |
using distortos::MessageQueue< T >::EntryStorage = internal::MessageQueueBase::EntryStorage |
type of uninitialized storage for Entry with link
using distortos::MessageQueue< T >::EntryStorageUniquePointer = internal::MessageQueueBase::EntryStorageUniquePointer |
import EntryStorageUniquePointer type from internal::MessageQueueBase class
using distortos::MessageQueue< T >::ValueStorage = internal::MessageQueueBase::ValueStorage<T> |
type of uninitialized storage for value
using distortos::MessageQueue< T >::ValueStorageUniquePointer = std::unique_ptr<ValueStorage[], internal::MessageQueueBase::ValueStorageUniquePointer::deleter_type> |
unique_ptr (with deleter) to ValueStorage[]
using distortos::MessageQueue< T >::ValueType = T |
type of data in queue
|
inline |
MessageQueue's constructor.
[in] | entryStorageUniquePointer | is a rvalue reference to EntryStorageUniquePointer with storage for queue entries (sufficiently large for maxElements EntryStorage objects) and appropriate deleter |
[in] | valueStorageUniquePointer | is a rvalue reference to ValueStorageUniquePointer with storage for queue elements (sufficiently large for maxElements, each sizeof(T) bytes long) and appropriate deleter |
[in] | maxElements | is the number of elements in entryStorage and valueStorage arrays |
distortos::MessageQueue< T >::~MessageQueue | ( | ) |
MessageQueue's destructor.
Pops all remaining elements from the queue.
|
inline |
Emplaces the element in the queue.
Similar to mq_send() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#
Args | are types of arguments for constructor of T |
[in] | priority | is the priority of new element |
[in] | args | are arguments for constructor of T |
|
private |
Emplaces the element in the queue.
Internal version - builds the Functor object.
Args | are types of arguments for constructor of T |
[in] | waitSemaphoreFunctor | is a reference to SemaphoreFunctor which will be executed with pushSemaphore_ |
[in] | priority | is the priority of new element |
[in] | args | are arguments for constructor of T |
|
inline |
|
inline |
Pops oldest element with highest priority from the queue.
Similar to mq_receive() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html#
[out] | priority | is a reference to variable that will be used to return priority of popped value |
[out] | value | is a reference to object that will be used to return popped value, its contents are swapped with the value in the queue's storage and destructed when no longer needed |
|
private |
Pops oldest element with highest priority from the queue.
Internal version - builds the Functor object.
[in] | waitSemaphoreFunctor | is a reference to SemaphoreFunctor which will be executed with popSemaphore_ |
[out] | priority | is a reference to variable that will be used to return priority of popped value |
[out] | value | is a reference to object that will be used to return popped value, its contents are swapped with the value in the queue's storage and destructed when no longer needed |
|
inline |
Pushes the element to the queue.
Similar to mq_send() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#
[in] | priority | is the priority of new element |
[in] | value | is a reference to object that will be pushed, value in queue's storage is copy-constructed |
|
inline |
Pushes the element to the queue.
Similar to mq_send() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#
[in] | priority | is the priority of new element |
[in] | value | is a rvalue reference to object that will be pushed, value in queue's storage is move-constructed |
|
private |
Pushes the element to the queue.
Internal version - builds the Functor object.
[in] | waitSemaphoreFunctor | is a reference to SemaphoreFunctor which will be executed with pushSemaphore_ |
[in] | priority | is the priority of new element |
[in] | value | is a reference to object that will be pushed, value in queue's storage is copy-constructed |
|
private |
Pushes the element to the queue.
Internal version - builds the Functor object.
[in] | waitSemaphoreFunctor | is a reference to SemaphoreFunctor which will be executed with pushSemaphore_ |
[in] | priority | is the priority of new element |
[in] | value | is a rvalue reference to object that will be pushed, value in queue's storage is move-constructed |
|
inline |
Tries to emplace the element in the queue.
Similar to mq_send() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#
Args | are types of arguments for constructor of T |
[in] | priority | is the priority of new element |
[in] | args | are arguments for constructor of T |
|
inline |
Tries to emplace the element in the queue for a given duration of time.
Similar to mq_timedsend() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#
Args | are types of arguments for constructor of T |
[in] | duration | is the duration after which the wait will be terminated without emplacing the element |
[in] | priority | is the priority of new element |
[in] | args | are arguments for constructor of T |
|
inline |
Tries to emplace the element in the queue for a given duration of time.
Template variant of MessageQueue::tryEmplaceFor(TickClock::duration, uint8_t, Args&&...).
Rep | is type of tick counter |
Period | is std::ratio type representing the tick period of the clock, seconds |
Args | are types of arguments for constructor of T |
[in] | duration | is the duration after which the wait will be terminated without emplacing the element |
[in] | priority | is the priority of new element |
[in] | args | are arguments for constructor of T |
|
inline |
Tries to emplace the element in the queue until a given time point.
Similar to mq_timedsend() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#
Args | are types of arguments for constructor of T |
[in] | timePoint | is the time point at which the call will be terminated without emplacing the element |
[in] | priority | is the priority of new element |
[in] | args | are arguments for constructor of T |
|
inline |
Tries to emplace the element in the queue until a given time point.
Template variant of FifoQueue::tryEmplaceUntil(TickClock::time_point, uint8_t, Args&&...).
Duration | is a std::chrono::duration type used to measure duration |
Args | are types of arguments for constructor of T |
[in] | timePoint | is the time point at which the call will be terminated without emplacing the element |
[in] | priority | is the priority of new element |
[in] | args | are arguments for constructor of T |
|
inline |
Tries to pop oldest element with highest priority from the queue.
Similar to mq_receive() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html#
[out] | priority | is a reference to variable that will be used to return priority of popped value |
[out] | value | is a reference to object that will be used to return popped value, its contents are swapped with the value in the queue's storage and destructed when no longer needed |
|
inline |
Tries to pop oldest element with highest priority from the queue for a given duration of time.
Similar to mq_timedreceive() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html#
[in] | duration | is the duration after which the call will be terminated without popping the element |
[out] | priority | is a reference to variable that will be used to return priority of popped value |
[out] | value | is a reference to object that will be used to return popped value, its contents are swapped with the value in the queue's storage and destructed when no longer needed |
|
inline |
Tries to pop oldest element with highest priority from the queue for a given duration of time.
Template variant of tryPopFor(TickClock::duration, uint8_t&, T&).
Rep | is type of tick counter |
Period | is std::ratio type representing the tick period of the clock, seconds |
[in] | duration | is the duration after which the call will be terminated without popping the element |
[out] | priority | is a reference to variable that will be used to return priority of popped value |
[out] | value | is a reference to object that will be used to return popped value, its contents are swapped with the value in the queue's storage and destructed when no longer needed |
|
inline |
Tries to pop oldest element with highest priority from the queue until a given time point.
Similar to mq_timedreceive() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html#
[in] | timePoint | is the time point at which the call will be terminated without popping the element |
[out] | priority | is a reference to variable that will be used to return priority of popped value |
[out] | value | is a reference to object that will be used to return popped value, its contents are swapped with the value in the queue's storage and destructed when no longer needed |
|
inline |
Tries to pop oldest element with highest priority from the queue until a given time point.
Template variant of tryPopUntil(TickClock::time_point, uint8_t&, T&).
Duration | is a std::chrono::duration type used to measure duration |
[in] | timePoint | is the time point at which the call will be terminated without popping the element |
[out] | priority | is a reference to variable that will be used to return priority of popped value |
[out] | value | is a reference to object that will be used to return popped value, its contents are swapped with the value in the queue's storage and destructed when no longer needed |
|
inline |
Tries to push the element to the queue.
Similar to mq_send() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#
[in] | priority | is the priority of new element |
[in] | value | is a reference to object that will be pushed, value in queue's storage is copy-constructed |
|
inline |
Tries to push the element to the queue.
Similar to mq_send() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#
[in] | priority | is the priority of new element |
[in] | value | is a rvalue reference to object that will be pushed, value in queue's storage is move-constructed |
|
inline |
Tries to push the element to the queue for a given duration of time.
Similar to mq_timedsend() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#
[in] | duration | is the duration after which the wait will be terminated without pushing the element |
[in] | priority | is the priority of new element |
[in] | value | is a reference to object that will be pushed, value in queue's storage is copy-constructed |
|
inline |
Tries to push the element to the queue for a given duration of time.
Template variant of tryPushFor(TickClock::duration, uint8_t, const T&).
Rep | is type of tick counter |
Period | is std::ratio type representing the tick period of the clock, seconds |
[in] | duration | is the duration after which the wait will be terminated without pushing the element |
[in] | priority | is the priority of new element |
[in] | value | is a reference to object that will be pushed, value in queue's storage is copy-constructed |
|
inline |
Tries to push the element to the queue for a given duration of time.
Similar to mq_timedsend() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#
[in] | duration | is the duration after which the wait will be terminated without pushing the element |
[in] | priority | is the priority of new element |
[in] | value | is a rvalue reference to object that will be pushed, value in queue's storage is move-constructed |
|
inline |
Tries to push the element to the queue for a given duration of time.
Template variant of tryPushFor(TickClock::duration, uint8_t, T&&).
Rep | is type of tick counter |
Period | is std::ratio type representing the tick period of the clock, seconds |
[in] | duration | is the duration after which the call will be terminated without pushing the element |
[in] | priority | is the priority of new element |
[in] | value | is a rvalue reference to object that will be pushed, value in queue's storage is move-constructed |
|
inline |
Tries to push the element to the queue until a given time point.
Similar to mq_timedsend() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#
[in] | timePoint | is the time point at which the call will be terminated without pushing the element |
[in] | priority | is the priority of new element |
[in] | value | is a reference to object that will be pushed, value in queue's storage is copy-constructed |
|
inline |
Tries to push the element to the queue until a given time point.
Template variant of tryPushUntil(TickClock::time_point, uint8_t, const T&).
Duration | is a std::chrono::duration type used to measure duration |
[in] | timePoint | is the time point at which the call will be terminated without pushing the element |
[in] | priority | is the priority of new element |
[in] | value | is a reference to object that will be pushed, value in queue's storage is copy-constructed |
|
inline |
Tries to push the element to the queue until a given time point.
Similar to mq_timedsend() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#
[in] | timePoint | is the time point at which the call will be terminated without pushing the element |
[in] | priority | is the priority of new element |
[in] | value | is a rvalue reference to object that will be pushed, value in queue's storage is move-constructed |
|
inline |
Tries to push the element to the queue until a given time point.
Template variant of tryPushUntil(TickClock::time_point, uint8_t, T&&).
Duration | is a std::chrono::duration type used to measure duration |
[in] | timePoint | is the time point at which the call will be terminated without pushing the element |
[in] | priority | is the priority of new element |
[in] | value | is a rvalue reference to object that will be pushed, value in queue's storage is move-constructed |
|
private |
contained internal::MessageQueueBase object which implements whole functionality