distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
distortos::internal::MessageQueueBase Class Reference

MessageQueueBase class implements basic functionality of MessageQueue template class. More...

#include "distortos/internal/synchronization/MessageQueueBase.hpp"

Collaboration diagram for distortos::internal::MessageQueueBase:
[legend]

Classes

struct  DescendingPriority
 functor which gives descending priority order of elements on the list More...
 
struct  Entry
 entry in the MessageQueueBase More...
 
class  InternalFunctor
 InternalFunctor is a type-erased interface for functors which execute common code of pop() and push() operations. More...
 

Public Types

using EntryStorage = typename std::aligned_storage< sizeof(Entry), alignof(Entry)>::type
 type of uninitialized storage for Entry More...
 
using EntryStorageUniquePointer = std::unique_ptr< EntryStorage[], void(&)(EntryStorage *)>
 unique_ptr (with deleter) to EntryStorage[] More...
 
template<typename T >
using ValueStorage = typename std::aligned_storage< sizeof(T), alignof(T)>::type
 
using ValueStorageUniquePointer = std::unique_ptr< void, void(&)(void *)>
 unique_ptr (with deleter) to storage More...
 
using EntryList = estd::SortedIntrusiveForwardList< DescendingPriority, Entry, &Entry::node >
 type of entry list More...
 
using FreeEntryList = EntryList::UnsortedIntrusiveForwardList
 type of free entry list More...
 

Public Member Functions

 MessageQueueBase (EntryStorageUniquePointer &&entryStorageUniquePointer, ValueStorageUniquePointer &&valueStorageUniquePointer, size_t elementSize, size_t maxElements)
 MessageQueueBase's constructor. More...
 
 ~MessageQueueBase ()
 MessageQueueBase's destructor. More...
 
size_t getCapacity () const
 
int pop (const SemaphoreFunctor &waitSemaphoreFunctor, uint8_t &priority, const QueueFunctor &functor)
 Implementation of pop() using type-erased functor. More...
 
int push (const SemaphoreFunctor &waitSemaphoreFunctor, uint8_t priority, const QueueFunctor &functor)
 Implementation of push() using type-erased functor. More...
 

Private Member Functions

int popPush (const SemaphoreFunctor &waitSemaphoreFunctor, const InternalFunctor &internalFunctor, Semaphore &waitSemaphore, Semaphore &postSemaphore)
 Implementation of pop() and push() using type-erased internal functor. More...
 

Private Attributes

Semaphore popSemaphore_
 semaphore guarding access to "pop" functions - its value is equal to the number of available elements More...
 
Semaphore pushSemaphore_
 semaphore guarding access to "push" functions - its value is equal to the number of free slots More...
 
const EntryStorageUniquePointer entryStorageUniquePointer_
 storage for queue entries More...
 
const ValueStorageUniquePointer valueStorageUniquePointer_
 storage for queue elements More...
 
EntryList entryList_
 list of available entries, sorted in descending order of priority More...
 
FreeEntryList freeEntryList_
 list of "free" entries More...
 

Detailed Description

MessageQueueBase class implements basic functionality of MessageQueue template class.

Member Typedef Documentation

◆ EntryList

◆ EntryStorage

using distortos::internal::MessageQueueBase::EntryStorage = typename std::aligned_storage<sizeof(Entry), alignof(Entry)>::type

type of uninitialized storage for Entry

◆ EntryStorageUniquePointer

unique_ptr (with deleter) to EntryStorage[]

◆ FreeEntryList

◆ ValueStorage

template<typename T >
using distortos::internal::MessageQueueBase::ValueStorage = typename std::aligned_storage<sizeof(T), alignof(T)>::type

type of uninitialized storage for value

Template Parameters
Tis the type of data in queue

◆ ValueStorageUniquePointer

using distortos::internal::MessageQueueBase::ValueStorageUniquePointer = std::unique_ptr<void, void(&)(void*)>

unique_ptr (with deleter) to storage

Constructor & Destructor Documentation

◆ MessageQueueBase()

distortos::internal::MessageQueueBase::MessageQueueBase ( EntryStorageUniquePointer &&  entryStorageUniquePointer,
ValueStorageUniquePointer &&  valueStorageUniquePointer,
size_t  elementSize,
size_t  maxElements 
)

MessageQueueBase's constructor.

Parameters
[in]entryStorageUniquePointeris a rvalue reference to EntryStorageUniquePointer with storage for queue entries (sufficiently large for maxElements EntryStorage objects) and appropriate deleter
[in]valueStorageUniquePointeris a rvalue reference to ValueStorageUniquePointer with storage for queue elements (sufficiently large for maxElements, each elementSize bytes long) and appropriate deleter
[in]elementSizeis the size of single queue element, bytes
[in]maxElementsis the number of elements in entryStorage array and valueStorage memory block

◆ ~MessageQueueBase()

distortos::internal::MessageQueueBase::~MessageQueueBase ( )

MessageQueueBase's destructor.

Member Function Documentation

◆ getCapacity()

size_t distortos::internal::MessageQueueBase::getCapacity ( ) const
inline
Returns
maximum number of elements in queue
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop()

int distortos::internal::MessageQueueBase::pop ( const SemaphoreFunctor waitSemaphoreFunctor,
uint8_t &  priority,
const QueueFunctor functor 
)

Implementation of pop() using type-erased functor.

Parameters
[in]waitSemaphoreFunctoris a reference to SemaphoreFunctor which will be executed with popSemaphore_
[out]priorityis a reference to variable that will be used to return priority of popped value
[in]functoris a reference to QueueFunctor which will execute actions related to popping - it will get a pointer to storage with element
Returns
0 if element was popped successfully, error code otherwise:
  • error codes returned by waitSemaphoreFunctor's operator() call;
  • error codes returned by Semaphore::post();
Here is the call graph for this function:
Here is the caller graph for this function:

◆ popPush()

int distortos::internal::MessageQueueBase::popPush ( const SemaphoreFunctor waitSemaphoreFunctor,
const InternalFunctor internalFunctor,
Semaphore waitSemaphore,
Semaphore postSemaphore 
)
private

Implementation of pop() and push() using type-erased internal functor.

Parameters
[in]waitSemaphoreFunctoris a reference to SemaphoreFunctor which will be executed with waitSemaphore
[in]internalFunctoris a reference to InternalFunctor which will execute actions related to popping/pushing
[in]waitSemaphoreis a reference to semaphore that will be waited for, popSemaphore_ for pop(), pushSemaphore_ for push()
[in]postSemaphoreis a reference to semaphore that will be posted after the operation, pushSemaphore_ for pop(), popSemaphore_ for push()
Returns
0 if operation was successful, error code otherwise:
  • error codes returned by waitSemaphoreFunctor's operator() call;
  • error codes returned by Semaphore::post();
Here is the call graph for this function:
Here is the caller graph for this function:

◆ push()

int distortos::internal::MessageQueueBase::push ( const SemaphoreFunctor waitSemaphoreFunctor,
uint8_t  priority,
const QueueFunctor functor 
)

Implementation of push() using type-erased functor.

Parameters
[in]waitSemaphoreFunctoris a reference to SemaphoreFunctor which will be executed with pushSemaphore_
[in]priorityis the priority of new element
[in]functoris a reference to QueueFunctor which will execute actions related to pushing - it will get a pointer to storage for element
Returns
0 if element was pushed successfully, error code otherwise:
  • error codes returned by waitSemaphoreFunctor's operator() call;
  • error codes returned by Semaphore::post();
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ entryList_

EntryList distortos::internal::MessageQueueBase::entryList_
private

list of available entries, sorted in descending order of priority

◆ entryStorageUniquePointer_

const EntryStorageUniquePointer distortos::internal::MessageQueueBase::entryStorageUniquePointer_
private

storage for queue entries

◆ freeEntryList_

FreeEntryList distortos::internal::MessageQueueBase::freeEntryList_
private

list of "free" entries

◆ popSemaphore_

Semaphore distortos::internal::MessageQueueBase::popSemaphore_
private

semaphore guarding access to "pop" functions - its value is equal to the number of available elements

◆ pushSemaphore_

Semaphore distortos::internal::MessageQueueBase::pushSemaphore_
private

semaphore guarding access to "push" functions - its value is equal to the number of free slots

◆ valueStorageUniquePointer_

const ValueStorageUniquePointer distortos::internal::MessageQueueBase::valueStorageUniquePointer_
private

storage for queue elements


The documentation for this class was generated from the following files: