Argon RTOS  1.3.0
Tiny embedded real-time kernel
Ar::StaticQueue< T, N > Class Template Reference

#include <ar_classes.h>

+ Inheritance diagram for Ar::StaticQueue< T, N >:

Description

template<typename T, unsigned N>
class Ar::StaticQueue< T, N >

Template class to help statically allocate a Queue.

This template class helps create a Queue instance by defining a static array of queue elements. The array length is one of the template parameters.

Example of creating a queue and adding an element:

// MyQueueType holds up to five uint32_t elements.
typedef StaticQueue<uint32_t, 5> MyQueueType;
MyQueueType q; // Can statically allocate MyQueueType!
q.init("my queue");
uint32_t element = 512;
q.send(element);
q.send(1024);
s = q.receive(&element);
element = q.receive(&s);
Parameters
TThe queue element type.
NMaximum number of elements the queue will hold.
+ Collaboration diagram for Ar::StaticQueue< T, N >:

Public Member Functions

 StaticQueue ()
 Default constructor.
 
 StaticQueue (const char *name)
 Constructor.
 
ar_status_t init (const char *name)
 Initialiser method.
 
ar_status_t receive (T *element, uint32_t timeout=kArInfiniteTimeout)
 Remove an item from the queue. More...
 
receive (uint32_t timeout=kArInfiniteTimeout, ar_status_t *resultStatus=NULL)
 Alternate form of typed receive. More...
 
ar_status_t send (T element, uint32_t timeout=kArInfiniteTimeout)
 Add an item to the queue. More...
 
- Public Member Functions inherited from Ar::Queue
 Queue ()
 Default constructor.
 
 Queue (const char *name, void *storage, unsigned elementSize, unsigned capacity)
 Constructor.
 
 ~Queue ()
 Queue cleanup.
 
unsigned getCount () const
 Returns the current number of elements in the queue.
 
const char * getName () const
 Get the queue's name.
 
ar_status_t init (const char *name, void *storage, unsigned elementSize, unsigned capacity)
 Queue initialiser. More...
 
bool isEmpty () const
 Returns whether the queue is currently empty.
 
ar_status_t receive (void *element, uint32_t timeout=kArInfiniteTimeout)
 Remove an item from the queue. More...
 
ar_status_t send (const void *element, uint32_t timeout=kArInfiniteTimeout)
 Add an item to the queue. More...
 

Protected Attributes

m_storage [N]
 Static storage for the queue elements.
 

Additional Inherited Members

- Public Attributes inherited from ar_queue_t
unsigned m_capacity
 Maximum number of elements the queue can hold.
 
unsigned m_count
 Current number of elements in the queue.
 
uint8_t * m_elements
 Pointer to element storage.
 
unsigned m_elementSize
 Number of bytes occupied by each element.
 
unsigned m_head
 Index of queue head.
 
const char * m_name
 Name of the queue.
 
ar_list_t m_receiveBlockedList
 List of threads blocked waiting to receive data.
 
ar_runloop_t * m_runLoop
 Runloop the queue is bound to.
 
ar_runloop_queue_handler_t m_runLoopHandler
 Handler function.
 
void * m_runLoopHandlerParam
 User parameter for handler function.
 
ar_list_node_t m_runLoopNode
 List node for the runloop's queue list.
 
ar_list_t m_sendBlockedList
 List of threads blocked waiting to send.
 
unsigned m_tail
 Index of queue tail.
 

Member Function Documentation

◆ receive() [1/2]

template<typename T, unsigned N>
ar_status_t Ar::StaticQueue< T, N >::receive ( T *  element,
uint32_t  timeout = kArInfiniteTimeout 
)
inline

Remove an item from the queue.

Parameters
[out]element
timeoutThe maximum number of milliseconds that the caller is willing to wait in a blocked state before an element is received. If this value is 0, or kArNoTimeout, then this method will return immediately if the queue is empty. Setting the timeout to kArInfiniteTimeout will cause the thread to wait forever for receive an element.
Return values
kArSuccess
kArQueueEmptyError

◆ receive() [2/2]

template<typename T, unsigned N>
T Ar::StaticQueue< T, N >::receive ( uint32_t  timeout = kArInfiniteTimeout,
ar_status_t resultStatus = NULL 
)
inline

Alternate form of typed receive.

Parameters
[out]resultStatusThe status of the receive operation is placed here. May be NULL, in which case no status is returned.
timeoutMaximum time in ticks to wait for a queue element.

◆ send()

template<typename T, unsigned N>
ar_status_t Ar::StaticQueue< T, N >::send ( element,
uint32_t  timeout = kArInfiniteTimeout 
)
inline

Add an item to the queue.

The caller will block if the queue is full.

Parameters
elementPointer to the element to post to the queue. The element size was specified in the init() call.
timeoutThe maximum number of milliseconds that the caller is willing to wait in a blocked state before the element can be sent. If this value is 0, or kArNoTimeout, then this method will return immediately if the queue is full. Setting the timeout to kArInfiniteTimeout will cause the thread to wait forever for a chance to send.
Return values
kArSuccess
kArQueueFullError