distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
distortos::FifoQueue< T > Class Template Reference

FifoQueue class is a simple FIFO 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::FifoQueueBase. More...

#include <FifoQueue.hpp>

Inheritance diagram for distortos::FifoQueue< T >:
[legend]
Collaboration diagram for distortos::FifoQueue< T >:
[legend]

Public Types

using Storage = typename std::aligned_storage< sizeof(T), alignof(T)>::type
 type of uninitialized storage for data More...
 
using StorageUniquePointer = std::unique_ptr< Storage[], internal::FifoQueueBase::StorageUniquePointer::deleter_type >
 unique_ptr (with deleter) to Storage[] More...
 

Public Member Functions

 FifoQueue (StorageUniquePointer &&storageUniquePointer, const size_t maxElements)
 FifoQueue's constructor. More...
 
 ~FifoQueue ()
 FifoQueue's destructor. More...
 
template<typename... Args>
int emplace (Args &&... args)
 Emplaces the element in the queue. More...
 
int pop (T &value)
 Pops the oldest (first) element from the queue. More...
 
int push (const T &value)
 Pushes the element to the queue. More...
 
int push (T &&value)
 Pushes the element to the queue. More...
 
template<typename... Args>
int tryEmplace (Args &&... args)
 Tries to emplace the element in the queue. More...
 
template<typename... Args>
int tryEmplaceFor (const TickClock::duration duration, 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, 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, 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, Args &&... args)
 Tries to emplace the element in the queue until a given time point. More...
 
int tryPop (T &value)
 Tries to pop the oldest (first) element from the queue. More...
 
int tryPopFor (const TickClock::duration duration, T &value)
 Tries to pop the oldest (first) element from the queue for a given duration of time. More...
 
template<typename Rep , typename Period >
int tryPopFor (const std::chrono::duration< Rep, Period > duration, T &value)
 Tries to pop the oldest (first) element from the queue for a given duration of time. More...
 
int tryPopUntil (const TickClock::time_point timePoint, T &value)
 Tries to pop the oldest (first) element from the queue until a given time point. More...
 
template<typename Duration >
int tryPopUntil (const std::chrono::time_point< TickClock, Duration > timePoint, T &value)
 Tries to pop the oldest (first) element from the queue until a given time point. More...
 
int tryPush (const T &value)
 Tries to push the element to the queue. More...
 
int tryPush (T &&value)
 Tries to push the element to the queue. More...
 
int tryPushFor (const TickClock::duration duration, 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 T &value)
 Tries to push the element to the queue for a given duration of time. More...
 
int tryPushFor (const TickClock::duration duration, 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, 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 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 T &value)
 Tries to push the element to the queue until a given time point. More...
 
int tryPushUntil (const TickClock::time_point timePoint, 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, 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, Args &&... args)
 Emplaces the element in the queue. More...
 
int popInternal (const internal::SemaphoreFunctor &waitSemaphoreFunctor, T &value)
 Pops the oldest (first) element from the queue. More...
 
int pushInternal (const internal::SemaphoreFunctor &waitSemaphoreFunctor, const T &value)
 Pushes the element to the queue. More...
 
int pushInternal (const internal::SemaphoreFunctor &waitSemaphoreFunctor, T &&value)
 Pushes the element to the queue. More...
 

Private Attributes

internal::FifoQueueBase fifoQueueBase_
 contained internal::FifoQueueBase object which implements whole functionality More...
 

Detailed Description

template<typename T>
class distortos::FifoQueue< T >

FifoQueue class is a simple FIFO 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::FifoQueueBase.

Template Parameters
Tis the type of data in queue

Member Typedef Documentation

◆ Storage

template<typename T>
using distortos::FifoQueue< T >::Storage = typename std::aligned_storage<sizeof(T), alignof(T)>::type

type of uninitialized storage for data

◆ StorageUniquePointer

template<typename T>
using distortos::FifoQueue< T >::StorageUniquePointer = std::unique_ptr<Storage[], internal::FifoQueueBase::StorageUniquePointer::deleter_type>

unique_ptr (with deleter) to Storage[]

Constructor & Destructor Documentation

◆ FifoQueue()

template<typename T>
distortos::FifoQueue< T >::FifoQueue ( StorageUniquePointer &&  storageUniquePointer,
const size_t  maxElements 
)
inline

FifoQueue's constructor.

Parameters
[in]storageUniquePointeris a rvalue reference to StorageUniquePointer with storage for queue elements (sufficiently large for maxElements, each sizeof(T) bytes long) and appropriate deleter
[in]maxElementsis the number of elements in storage array

◆ ~FifoQueue()

template<typename T >
distortos::FifoQueue< T >::~FifoQueue ( )

FifoQueue's destructor.

Pops all remaining elements from the queue.

Here is the caller graph for this function:

Member Function Documentation

◆ emplace()

template<typename T>
template<typename... Args>
int distortos::FifoQueue< T >::emplace ( Args &&...  args)
inline

Emplaces the element in the queue.

Note
This function requires GCC 4.9.
Warning
This function must not be called from interrupt context!
Template Parameters
Argsare types of arguments for constructor of T
Parameters
[in]argsare arguments for constructor of T
Returns
zero if element was emplaced successfully, error code otherwise:

◆ emplaceInternal()

template<typename T >
template<typename... Args>
int distortos::FifoQueue< T >::emplaceInternal ( const internal::SemaphoreFunctor waitSemaphoreFunctor,
Args &&...  args 
)
private

Emplaces the element in the queue.

Internal version - builds the Functor object.

Note
This function requires GCC 4.9.
Template Parameters
Argsare types of arguments for constructor of T
Parameters
[in]waitSemaphoreFunctoris a reference to SemaphoreFunctor which will be executed with pushSemaphore_
[in]argsare arguments for constructor of T
Returns
zero if element was emplaced successfully, error code otherwise:
  • error codes returned by waitSemaphoreFunctor's operator() call;
  • error codes returned by Semaphore::post();
Here is the caller graph for this function:

◆ pop()

template<typename T>
int distortos::FifoQueue< T >::pop ( T &  value)
inline

Pops the oldest (first) element from the queue.

Warning
This function must not be called from interrupt context!
Parameters
[out]valueis 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
Returns
zero if element was popped successfully, error code otherwise:

◆ popInternal()

template<typename T>
int distortos::FifoQueue< T >::popInternal ( const internal::SemaphoreFunctor waitSemaphoreFunctor,
T &  value 
)
private

Pops the oldest (first) element from the queue.

Internal version - builds the Functor object.

Parameters
[in]waitSemaphoreFunctoris a reference to SemaphoreFunctor which will be executed with popSemaphore_
[out]valueis 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
Returns
zero 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 caller graph for this function:

◆ push() [1/2]

template<typename T>
int distortos::FifoQueue< T >::push ( const T &  value)
inline

Pushes the element to the queue.

Warning
This function must not be called from interrupt context!
Parameters
[in]valueis a reference to object that will be pushed, value in queue's storage is copy-constructed
Returns
zero if element was pushed successfully, error code otherwise:

◆ push() [2/2]

template<typename T>
int distortos::FifoQueue< T >::push ( T &&  value)
inline

Pushes the element to the queue.

Warning
This function must not be called from interrupt context!
Parameters
[in]valueis a rvalue reference to object that will be pushed, value in queue's storage is move-constructed
Returns
zero if element was pushed successfully, error code otherwise:

◆ pushInternal() [1/2]

template<typename T>
int distortos::FifoQueue< T >::pushInternal ( const internal::SemaphoreFunctor waitSemaphoreFunctor,
const T &  value 
)
private

Pushes the element to the queue.

Internal version - builds the Functor object.

Parameters
[in]waitSemaphoreFunctoris a reference to SemaphoreFunctor which will be executed with pushSemaphore_
[in]valueis a reference to object that will be pushed, value in queue's storage is copy-constructed
Returns
zero 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 caller graph for this function:

◆ pushInternal() [2/2]

template<typename T>
int distortos::FifoQueue< T >::pushInternal ( const internal::SemaphoreFunctor waitSemaphoreFunctor,
T &&  value 
)
private

Pushes the element to the queue.

Internal version - builds the Functor object.

Parameters
[in]waitSemaphoreFunctoris a reference to SemaphoreFunctor which will be executed with pushSemaphore_
[in]valueis a rvalue reference to object that will be pushed, value in queue's storage is move-constructed
Returns
zero if element was pushed successfully, error code otherwise:
  • error codes returned by waitSemaphoreFunctor's operator() call;
  • error codes returned by Semaphore::post();

◆ tryEmplace()

template<typename T>
template<typename... Args>
int distortos::FifoQueue< T >::tryEmplace ( Args &&...  args)
inline

Tries to emplace the element in the queue.

Note
This function requires GCC 4.9.
Template Parameters
Argsare types of arguments for constructor of T
Parameters
[in]argsare arguments for constructor of T
Returns
zero if element was emplaced successfully, error code otherwise:

◆ tryEmplaceFor() [1/2]

template<typename T>
template<typename... Args>
int distortos::FifoQueue< T >::tryEmplaceFor ( const TickClock::duration  duration,
Args &&...  args 
)
inline

Tries to emplace the element in the queue for a given duration of time.

Note
This function requires GCC 4.9.
Warning
This function must not be called from interrupt context!
Template Parameters
Argsare types of arguments for constructor of T
Parameters
[in]durationis the duration after which the wait will be terminated without emplacing the element
[in]argsare arguments for constructor of T
Returns
zero if element was emplaced successfully, error code otherwise:
Here is the caller graph for this function:

◆ tryEmplaceFor() [2/2]

template<typename T>
template<typename Rep , typename Period , typename... Args>
int distortos::FifoQueue< T >::tryEmplaceFor ( const std::chrono::duration< Rep, Period >  duration,
Args &&...  args 
)
inline

Tries to emplace the element in the queue for a given duration of time.

Template variant of FifoQueue::tryEmplaceFor(TickClock::duration, Args&&...).

Note
This function requires GCC 4.9.
Warning
This function must not be called from interrupt context!
Template Parameters
Repis type of tick counter
Periodis std::ratio type representing the tick period of the clock, seconds
Argsare types of arguments for constructor of T
Parameters
[in]durationis the duration after which the wait will be terminated without emplacing the element
[in]argsare arguments for constructor of T
Returns
zero if element was emplaced successfully, error code otherwise:

◆ tryEmplaceUntil() [1/2]

template<typename T>
template<typename... Args>
int distortos::FifoQueue< T >::tryEmplaceUntil ( const TickClock::time_point  timePoint,
Args &&...  args 
)
inline

Tries to emplace the element in the queue until a given time point.

Note
This function requires GCC 4.9.
Warning
This function must not be called from interrupt context!
Template Parameters
Argsare types of arguments for constructor of T
Parameters
[in]timePointis the time point at which the call will be terminated without emplacing the element
[in]argsare arguments for constructor of T
Returns
zero if element was emplaced successfully, error code otherwise:
Here is the caller graph for this function:

◆ tryEmplaceUntil() [2/2]

template<typename T>
template<typename Duration , typename... Args>
int distortos::FifoQueue< T >::tryEmplaceUntil ( const std::chrono::time_point< TickClock, Duration >  timePoint,
Args &&...  args 
)
inline

Tries to emplace the element in the queue until a given time point.

Template variant of FifoQueue::tryEmplaceUntil(TickClock::time_point, Args&&...).

Note
This function requires GCC 4.9.
Warning
This function must not be called from interrupt context!
Template Parameters
Durationis a std::chrono::duration type used to measure duration
Argsare types of arguments for constructor of T
Parameters
[in]timePointis the time point at which the call will be terminated without emplacing the element
[in]argsare arguments for constructor of T
Returns
zero if element was emplaced successfully, error code otherwise:

◆ tryPop()

template<typename T>
int distortos::FifoQueue< T >::tryPop ( T &  value)
inline

Tries to pop the oldest (first) element from the queue.

Parameters
[out]valueis 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
Returns
zero if element was popped successfully, error code otherwise:
Here is the caller graph for this function:

◆ tryPopFor() [1/2]

template<typename T>
int distortos::FifoQueue< T >::tryPopFor ( const TickClock::duration  duration,
T &  value 
)
inline

Tries to pop the oldest (first) element from the queue for a given duration of time.

Warning
This function must not be called from interrupt context!
Parameters
[in]durationis the duration after which the call will be terminated without popping the element
[out]valueis 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
Returns
zero if element was popped successfully, error code otherwise:
Here is the caller graph for this function:

◆ tryPopFor() [2/2]

template<typename T>
template<typename Rep , typename Period >
int distortos::FifoQueue< T >::tryPopFor ( const std::chrono::duration< Rep, Period >  duration,
T &  value 
)
inline

Tries to pop the oldest (first) element from the queue for a given duration of time.

Template variant of tryPopFor(TickClock::duration, T&).

Warning
This function must not be called from interrupt context!
Template Parameters
Repis type of tick counter
Periodis std::ratio type representing the tick period of the clock, seconds
Parameters
[in]durationis the duration after which the call will be terminated without popping the element
[out]valueis 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
Returns
zero if element was popped successfully, error code otherwise:

◆ tryPopUntil() [1/2]

template<typename T>
int distortos::FifoQueue< T >::tryPopUntil ( const TickClock::time_point  timePoint,
T &  value 
)
inline

Tries to pop the oldest (first) element from the queue until a given time point.

Warning
This function must not be called from interrupt context!
Parameters
[in]timePointis the time point at which the call will be terminated without popping the element
[out]valueis 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
Returns
zero if element was popped successfully, error code otherwise:
Here is the caller graph for this function:

◆ tryPopUntil() [2/2]

template<typename T>
template<typename Duration >
int distortos::FifoQueue< T >::tryPopUntil ( const std::chrono::time_point< TickClock, Duration >  timePoint,
T &  value 
)
inline

Tries to pop the oldest (first) element from the queue until a given time point.

Template variant of tryPopUntil(TickClock::time_point, T&).

Warning
This function must not be called from interrupt context!
Template Parameters
Durationis a std::chrono::duration type used to measure duration
Parameters
[in]timePointis the time point at which the call will be terminated without popping the element
[out]valueis 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
Returns
zero if element was popped successfully, error code otherwise:

◆ tryPush() [1/2]

template<typename T>
int distortos::FifoQueue< T >::tryPush ( const T &  value)
inline

Tries to push the element to the queue.

Parameters
[in]valueis a reference to object that will be pushed, value in queue's storage is copy-constructed
Returns
zero if element was pushed successfully, error code otherwise:

◆ tryPush() [2/2]

template<typename T>
int distortos::FifoQueue< T >::tryPush ( T &&  value)
inline

Tries to push the element to the queue.

Parameters
[in]valueis a rvalue reference to object that will be pushed, value in queue's storage is move-constructed
Returns
zero if element was pushed successfully, error code otherwise:

◆ tryPushFor() [1/4]

template<typename T>
int distortos::FifoQueue< T >::tryPushFor ( const TickClock::duration  duration,
const T &  value 
)
inline

Tries to push the element to the queue for a given duration of time.

Warning
This function must not be called from interrupt context!
Parameters
[in]durationis the duration after which the wait will be terminated without pushing the element
[in]valueis a reference to object that will be pushed, value in queue's storage is copy-constructed
Returns
zero if element was pushed successfully, error code otherwise:
Here is the caller graph for this function:

◆ tryPushFor() [2/4]

template<typename T>
template<typename Rep , typename Period >
int distortos::FifoQueue< T >::tryPushFor ( const std::chrono::duration< Rep, Period >  duration,
const T &  value 
)
inline

Tries to push the element to the queue for a given duration of time.

Template variant of tryPushFor(TickClock::duration, const T&).

Warning
This function must not be called from interrupt context!
Template Parameters
Repis type of tick counter
Periodis std::ratio type representing the tick period of the clock, seconds
Parameters
[in]durationis the duration after which the wait will be terminated without pushing the element
[in]valueis a reference to object that will be pushed, value in queue's storage is copy-constructed
Returns
zero if element was pushed successfully, error code otherwise:

◆ tryPushFor() [3/4]

template<typename T>
int distortos::FifoQueue< T >::tryPushFor ( const TickClock::duration  duration,
T &&  value 
)
inline

Tries to push the element to the queue for a given duration of time.

Warning
This function must not be called from interrupt context!
Parameters
[in]durationis the duration after which the call will be terminated without pushing the element
[in]valueis a rvalue reference to object that will be pushed, value in queue's storage is move-constructed
Returns
zero if element was pushed successfully, error code otherwise:

◆ tryPushFor() [4/4]

template<typename T>
template<typename Rep , typename Period >
int distortos::FifoQueue< T >::tryPushFor ( const std::chrono::duration< Rep, Period >  duration,
T &&  value 
)
inline

Tries to push the element to the queue for a given duration of time.

Template variant of tryPushFor(TickClock::duration, T&&).

Warning
This function must not be called from interrupt context!
Template Parameters
Repis type of tick counter
Periodis std::ratio type representing the tick period of the clock, seconds
Parameters
[in]durationis the duration after which the call will be terminated without pushing the element
[in]valueis a rvalue reference to object that will be pushed, value in queue's storage is move-constructed
Returns
zero if element was pushed successfully, error code otherwise:

◆ tryPushUntil() [1/4]

template<typename T>
int distortos::FifoQueue< T >::tryPushUntil ( const TickClock::time_point  timePoint,
const T &  value 
)
inline

Tries to push the element to the queue until a given time point.

Warning
This function must not be called from interrupt context!
Parameters
[in]timePointis the time point at which the call will be terminated without pushing the element
[in]valueis a reference to object that will be pushed, value in queue's storage is copy-constructed
Returns
zero if element was pushed successfully, error code otherwise:
Here is the caller graph for this function:

◆ tryPushUntil() [2/4]

template<typename T>
template<typename Duration >
int distortos::FifoQueue< T >::tryPushUntil ( const std::chrono::time_point< TickClock, Duration >  timePoint,
const T &  value 
)
inline

Tries to push the element to the queue until a given time point.

Template variant of tryPushUntil(TickClock::time_point, const T&).

Warning
This function must not be called from interrupt context!
Template Parameters
Durationis a std::chrono::duration type used to measure duration
Parameters
[in]timePointis the time point at which the call will be terminated without pushing the element
[in]valueis a reference to object that will be pushed, value in queue's storage is copy-constructed
Returns
zero if element was pushed successfully, error code otherwise:

◆ tryPushUntil() [3/4]

template<typename T>
int distortos::FifoQueue< T >::tryPushUntil ( const TickClock::time_point  timePoint,
T &&  value 
)
inline

Tries to push the element to the queue until a given time point.

Warning
This function must not be called from interrupt context!
Parameters
[in]timePointis the time point at which the call will be terminated without pushing the element
[in]valueis a rvalue reference to object that will be pushed, value in queue's storage is move-constructed
Returns
zero if element was pushed successfully, error code otherwise:

◆ tryPushUntil() [4/4]

template<typename T>
template<typename Duration >
int distortos::FifoQueue< T >::tryPushUntil ( const std::chrono::time_point< TickClock, Duration >  timePoint,
T &&  value 
)
inline

Tries to push the element to the queue until a given time point.

Template variant of tryPushUntil(TickClock::time_point, T&&).

Warning
This function must not be called from interrupt context!
Template Parameters
Durationis a std::chrono::duration type used to measure duration
Parameters
[in]timePointis the time point at which the call will be terminated without pushing the element
[in]valueis a rvalue reference to object that will be pushed, value in queue's storage is move-constructed
Returns
zero if element was pushed successfully, error code otherwise:

Member Data Documentation

◆ fifoQueueBase_

template<typename T>
internal::FifoQueueBase distortos::FifoQueue< T >::fifoQueueBase_
private

contained internal::FifoQueueBase object which implements whole functionality


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