distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
distortos::RawFifoQueue Class Reference

RawFifoQueue class is very similar to FifoQueue, but optimized for binary serializable types (like POD types). More...

#include <RawFifoQueue.hpp>

Inheritance diagram for distortos::RawFifoQueue:
[legend]
Collaboration diagram for distortos::RawFifoQueue:
[legend]

Public Types

using StorageUniquePointer = internal::FifoQueueBase::StorageUniquePointer
 unique_ptr (with deleter) to storage More...
 

Public Member Functions

 RawFifoQueue (StorageUniquePointer &&storageUniquePointer, size_t elementSize, size_t maxElements)
 RawFifoQueue's constructor. More...
 
int pop (void *buffer, size_t size)
 Pops the oldest (first) element from the queue. More...
 
template<typename T >
int pop (T &buffer)
 Pops the oldest (first) element from the queue. More...
 
int push (const void *data, size_t size)
 Pushes the element to the queue. More...
 
template<typename T >
int push (const T &data)
 Pushes the element to the queue. More...
 
int tryPop (void *buffer, size_t size)
 Tries to pop the oldest (first) element from the queue. More...
 
template<typename T >
int tryPop (T &buffer)
 Tries to pop the oldest (first) element from the queue. More...
 
int tryPopFor (TickClock::duration duration, void *buffer, size_t size)
 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, void *const buffer, const size_t size)
 Tries to pop the oldest (first) element from the queue for a given duration of time. More...
 
template<typename Rep , typename Period , typename T >
int tryPopFor (const std::chrono::duration< Rep, Period > duration, T &buffer)
 Tries to pop the oldest (first) element from the queue for a given duration of time. More...
 
int tryPopUntil (TickClock::time_point timePoint, void *buffer, size_t size)
 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, void *const buffer, const size_t size)
 Tries to pop the oldest (first) element from the queue until a given time point. More...
 
template<typename Duration , typename T >
int tryPopUntil (const std::chrono::time_point< TickClock, Duration > timePoint, T &buffer)
 Tries to pop the oldest (first) element from the queue until a given time point. More...
 
int tryPush (const void *data, size_t size)
 Tries to push the element to the queue. More...
 
template<typename T >
int tryPush (const T &data)
 Tries to push the element to the queue. More...
 
int tryPushFor (TickClock::duration duration, const void *data, size_t size)
 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 void *const data, const size_t size)
 Tries to push the element to the queue for a given duration of time. More...
 
template<typename Rep , typename Period , typename T >
int tryPushFor (const std::chrono::duration< Rep, Period > duration, const T &data)
 Tries to push the element to the queue for a given duration of time. More...
 
int tryPushUntil (TickClock::time_point timePoint, const void *data, size_t size)
 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 void *const data, const size_t size)
 Tries to push the element to the queue until a given time point. More...
 
template<typename Duration , typename T >
int tryPushUntil (const std::chrono::time_point< TickClock, Duration > timePoint, const T &data)
 Tries to push the element to the queue until a given time point. More...
 

Private Member Functions

int popInternal (const internal::SemaphoreFunctor &waitSemaphoreFunctor, void *buffer, size_t size)
 Pops the oldest (first) element from the queue. More...
 
int pushInternal (const internal::SemaphoreFunctor &waitSemaphoreFunctor, const void *data, size_t size)
 Pushes the element to the queue. More...
 

Private Attributes

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

Detailed Description

RawFifoQueue class is very similar to FifoQueue, but optimized for binary serializable types (like POD types).

Type T can be used with both RawFifoQueue and FifoQueue only when std::is_trivially_copyable<T>::value == true, otherwise only FifoQueue use is safe, while using RawFifoQueue results in undefined behavior.

Member Typedef Documentation

◆ StorageUniquePointer

Constructor & Destructor Documentation

◆ RawFifoQueue()

distortos::RawFifoQueue::RawFifoQueue ( StorageUniquePointer &&  storageUniquePointer,
size_t  elementSize,
size_t  maxElements 
)

RawFifoQueue's constructor.

Parameters
[in]storageUniquePointeris a rvalue reference to StorageUniquePointer 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 storage memory block

Member Function Documentation

◆ pop() [1/2]

int distortos::RawFifoQueue::pop ( void *  buffer,
size_t  size 
)

Pops the oldest (first) element from the queue.

Warning
This function must not be called from interrupt context!
Parameters
[out]bufferis a pointer to buffer for popped element
[in]sizeis the size of buffer, bytes - must be equal to the elementSize attribute of RawFifoQueue
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop() [2/2]

template<typename T >
int distortos::RawFifoQueue::pop ( T &  buffer)
inline

Pops the oldest (first) element from the queue.

Warning
This function must not be called from interrupt context!
Template Parameters
Tis the type of data popped from the queue
Parameters
[out]bufferis a reference to object that will be used to return popped value
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:

◆ popInternal()

int distortos::RawFifoQueue::popInternal ( const internal::SemaphoreFunctor waitSemaphoreFunctor,
void *  buffer,
size_t  size 
)
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]bufferis a pointer to buffer for popped element
[in]sizeis the size of buffer, bytes - must be equal to the elementSize attribute of RawFifoQueue
Returns
zero if element was popped successfully, error code otherwise:
  • EMSGSIZE - size doesn't match the elementSize attribute of RawFifoQueue;
  • 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() [1/2]

int distortos::RawFifoQueue::push ( const void *  data,
size_t  size 
)

Pushes the element to the queue.

Warning
This function must not be called from interrupt context!
Parameters
[in]datais a pointer to data that will be pushed to RawFifoQueue
[in]sizeis the size of data, bytes - must be equal to the elementSize attribute of RawFifoQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ push() [2/2]

template<typename T >
int distortos::RawFifoQueue::push ( const T &  data)
inline

Pushes the element to the queue.

Warning
This function must not be called from interrupt context!
Template Parameters
Tis the type of data pushed to the queue
Parameters
[in]datais a reference to data that will be pushed to RawFifoQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:

◆ pushInternal()

int distortos::RawFifoQueue::pushInternal ( const internal::SemaphoreFunctor waitSemaphoreFunctor,
const void *  data,
size_t  size 
)
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]datais a pointer to data that will be pushed to RawFifoQueue
[in]sizeis the size of data, bytes - must be equal to the elementSize attribute of RawFifoQueue
Returns
zero if element was pushed successfully, error code otherwise:
  • EMSGSIZE - size doesn't match the elementSize attribute of RawFifoQueue;
  • 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:

◆ tryPop() [1/2]

int distortos::RawFifoQueue::tryPop ( void *  buffer,
size_t  size 
)

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

Parameters
[out]bufferis a pointer to buffer for popped element
[in]sizeis the size of buffer, bytes - must be equal to the elementSize attribute of RawFifoQueue
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryPop() [2/2]

template<typename T >
int distortos::RawFifoQueue::tryPop ( T &  buffer)
inline

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

Template Parameters
Tis the type of data popped from the queue
Parameters
[out]bufferis a reference to object that will be used to return popped value
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPopFor() [1/3]

int distortos::RawFifoQueue::tryPopFor ( TickClock::duration  duration,
void *  buffer,
size_t  size 
)

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]bufferis a pointer to buffer for popped element
[in]sizeis the size of buffer, bytes - must be equal to the elementSize attribute of RawFifoQueue
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryPopFor() [2/3]

template<typename Rep , typename Period >
int distortos::RawFifoQueue::tryPopFor ( const std::chrono::duration< Rep, Period >  duration,
void *const  buffer,
const size_t  size 
)
inline

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

Template variant of tryPopFor(TickClock::duration, void*, size_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]bufferis a pointer to buffer for popped element
[in]sizeis the size of buffer, bytes - must be equal to the elementSize attribute of RawFifoQueue
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPopFor() [3/3]

template<typename Rep , typename Period , typename T >
int distortos::RawFifoQueue::tryPopFor ( const std::chrono::duration< Rep, Period >  duration,
T &  buffer 
)
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!
Template Parameters
Repis type of tick counter
Periodis std::ratio type representing the tick period of the clock, seconds
Tis the type of data popped from the queue
Parameters
[in]durationis the duration after which the call will be terminated without popping the element
[out]bufferis a reference to object that will be used to return popped value
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPopUntil() [1/3]

int distortos::RawFifoQueue::tryPopUntil ( TickClock::time_point  timePoint,
void *  buffer,
size_t  size 
)

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]bufferis a pointer to buffer for popped element
[in]sizeis the size of buffer, bytes - must be equal to the elementSize attribute of RawFifoQueue
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryPopUntil() [2/3]

template<typename Duration >
int distortos::RawFifoQueue::tryPopUntil ( const std::chrono::time_point< TickClock, Duration >  timePoint,
void *const  buffer,
const size_t  size 
)
inline

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

Template variant of tryPopUntil(TickClock::time_point, void*, size_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]bufferis a pointer to buffer for popped element
[in]sizeis the size of buffer, bytes - must be equal to the elementSize attribute of RawFifoQueue
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPopUntil() [3/3]

template<typename Duration , typename T >
int distortos::RawFifoQueue::tryPopUntil ( const std::chrono::time_point< TickClock, Duration >  timePoint,
T &  buffer 
)
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!
Template Parameters
Durationis a std::chrono::duration type used to measure duration
Tis the type of data popped from the queue
Parameters
[in]timePointis the time point at which the call will be terminated without popping the element
[out]bufferis a reference to object that will be used to return popped value
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPush() [1/2]

int distortos::RawFifoQueue::tryPush ( const void *  data,
size_t  size 
)

Tries to push the element to the queue.

Parameters
[in]datais a pointer to data that will be pushed to RawFifoQueue
[in]sizeis the size of data, bytes - must be equal to the elementSize attribute of RawFifoQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryPush() [2/2]

template<typename T >
int distortos::RawFifoQueue::tryPush ( const T &  data)
inline

Tries to push the element to the queue.

Template Parameters
Tis the type of data pushed to the queue
Parameters
[in]datais a reference to data that will be pushed to RawFifoQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPushFor() [1/3]

int distortos::RawFifoQueue::tryPushFor ( TickClock::duration  duration,
const void *  data,
size_t  size 
)

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]datais a pointer to data that will be pushed to RawFifoQueue
[in]sizeis the size of data, bytes - must be equal to the elementSize attribute of RawFifoQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryPushFor() [2/3]

template<typename Rep , typename Period >
int distortos::RawFifoQueue::tryPushFor ( const std::chrono::duration< Rep, Period >  duration,
const void *const  data,
const size_t  size 
)
inline

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

Template variant of tryPushFor(TickClock::duration, const void*, size_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]datais a pointer to data that will be pushed to RawFifoQueue
[in]sizeis the size of data, bytes - must be equal to the elementSize attribute of RawFifoQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPushFor() [3/3]

template<typename Rep , typename Period , typename T >
int distortos::RawFifoQueue::tryPushFor ( const std::chrono::duration< Rep, Period >  duration,
const T &  data 
)
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!
Template Parameters
Repis type of tick counter
Periodis std::ratio type representing the tick period of the clock, seconds
Tis the type of data pushed to the queue
Parameters
[in]durationis the duration after which the wait will be terminated without pushing the element
[in]datais a reference to data that will be pushed to RawFifoQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPushUntil() [1/3]

int distortos::RawFifoQueue::tryPushUntil ( TickClock::time_point  timePoint,
const void *  data,
size_t  size 
)

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]datais a pointer to data that will be pushed to RawFifoQueue
[in]sizeis the size of data, bytes - must be equal to the elementSize attribute of RawFifoQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryPushUntil() [2/3]

template<typename Duration >
int distortos::RawFifoQueue::tryPushUntil ( const std::chrono::time_point< TickClock, Duration >  timePoint,
const void *const  data,
const size_t  size 
)
inline

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

Template variant of tryPushUntil(TickClock::time_point, const void*, size_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]datais a pointer to data that will be pushed to RawFifoQueue
[in]sizeis the size of data, bytes - must be equal to the elementSize attribute of RawFifoQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPushUntil() [3/3]

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

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

Warning
This function must not be called from interrupt context!
Template Parameters
Durationis a std::chrono::duration type used to measure duration
Tis the type of data pushed to the queue
Parameters
[in]timePointis the time point at which the call will be terminated without pushing the element
[in]datais a reference to data that will be pushed to RawFifoQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:

Member Data Documentation

◆ fifoQueueBase_

internal::FifoQueueBase distortos::RawFifoQueue::fifoQueueBase_
private

contained internal::FifoQueueBase object which implements base functionality


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