The Queue class represents a collection of objects that are stored first by order of priority, and then in first-in, first-out (FIFO) order. More...
#include <Queue.h>
Public Member Functions | |
Queue () | |
Create and initialize a message Queue of objects of the parameterized type T and maximum capacity specified by queue_sz . More... | |
~Queue () | |
Queue destructor. More... | |
bool | empty () const |
Check if the queue is empty. More... | |
bool | full () const |
Check if the queue is full. More... | |
uint32_t | count () const |
Get number of queued messages in the queue. More... | |
bool | try_put (T *data, uint8_t prio=0) |
Inserts the given element to the end of the queue. More... | |
bool | try_put_for (Kernel::Clock::duration_u32 rel_time, T *data, uint8_t prio=0) |
Inserts the given element to the end of the queue. More... | |
osStatus | put (T *data, uint32_t millisec=0, uint8_t prio=0) |
Inserts the given element to the end of the queue. More... | |
bool | try_get (T **data_out) |
Get a message from the queue. More... | |
bool | try_get_for (Kernel::Clock::duration_u32 rel_time, T **data_out) |
Get a message or wait for a message from the queue. More... | |
osEvent | get (uint32_t millisec=osWaitForever) |
Get a message or wait for a message from the queue. More... | |
The Queue class represents a collection of objects that are stored first by order of priority, and then in first-in, first-out (FIFO) order.
You can use a queue when you need to store data and then access it in the same order that it has been stored. The order in which you retrieve the data is in order of descending priority. If multiple elements have the same priority, they are retrieved in FIFO order.
The object type stored in the queue can be an integer, pointer or a generic type given by the template parameter T.
T | Specifies the type of elements stored in the queue. |
queue_sz | Maximum number of messages that you can store in the queue. |
Queue | ( | ) |
~Queue | ( | ) |
uint32_t count | ( | ) | const |
bool empty | ( | ) | const |
bool full | ( | ) | const |
osEvent get | ( | uint32_t | millisec = osWaitForever | ) |
Get a message or wait for a message from the queue.
This function retrieves a message from the queue. The message is stored in the value field of the returned osEvent
object.
The timeout specified by the parameter millisec
specifies how long the function waits to retrieve the message from the queue.
The timeout parameter can have the following values:
Messages are retrieved in descending priority order. If two messages share the same priority level, they are retrieved in first-in, first-out (FIFO) order.
millisec | Timeout value. |
osStatus put | ( | T * | data, |
uint32_t | millisec = 0 , |
||
uint8_t | prio = 0 |
||
) |
Inserts the given element to the end of the queue.
This function puts the message pointed to by data
into the queue. The parameter prio
is used to sort the message according to their priority (higher numbers indicate higher priority) on insertion.
The timeout indicated by the parameter millisec
specifies how long the function blocks waiting for the message to be inserted into the queue.
The parameter millisec
can have the following values:
data | Pointer to the element to insert into the queue. |
millisec | Timeout for the operation to be executed, or 0 in case of no timeout. |
prio | Priority of the operation or 0 in case of default. (default: 0) |
bool try_get | ( | T ** | data_out | ) |
Get a message from the queue.
This function retrieves a message from the queue. The message is stored in the location pointed to be the parameter data_out
.
The function does not block, and returns immediately if the queue is empty.
[out] | data_out | Pointer to location to write the element retrieved from the queue. |
bool try_get_for | ( | Kernel::Clock::duration_u32 | rel_time, |
T ** | data_out | ||
) |
Get a message or wait for a message from the queue.
This function retrieves a message from the queue. The message is stored in the location pointed to be the parameter data_out
.
The timeout specified by the parameter rel_time
specifies how long the function waits to retrieve the message from the queue.
The timeout parameter can have the following values:
Messages are retrieved in descending priority order. If two messages share the same priority level, they are retrieved in first-in, first-out (FIFO) order.
rel_time | Timeout value. | |
[out] | data_out | Pointer to location to write the element retrieved from the queue. |
bool try_put | ( | T * | data, |
uint8_t | prio = 0 |
||
) |
Inserts the given element to the end of the queue.
This function puts the message pointed to by data
into the queue. The parameter prio
is used to sort the message according to their priority (higher numbers indicate higher priority) on insertion.
The function does not block, and returns immediately if the queue is full.
data | Pointer to the element to insert into the queue. |
prio | Priority of the operation or 0 in case of default. (default: 0) |
bool try_put_for | ( | Kernel::Clock::duration_u32 | rel_time, |
T * | data, | ||
uint8_t | prio = 0 |
||
) |
Inserts the given element to the end of the queue.
This function puts the message pointed to by data
into the queue. The parameter prio
is used to sort the message according to their priority (higher numbers indicate higher priority) on insertion.
The timeout indicated by the parameter rel_time
specifies how long the function blocks waiting for the message to be inserted into the queue.
The parameter rel_time
can have the following values:
try_put
instead.rel_time | Timeout for the operation to be executed. |
data | Pointer to the element to insert into the queue. |
prio | Priority of the operation or 0 in case of default. (default: 0) |