EtcPal  HEAD (unstable)
ETC Platform Abstraction Layer (EtcPal)
View other versions:
static_queue (RTOS queues)

Overview

Static C++ utilities for the queue (RTOS queues) module.

Provides a template class StaticQueue which can be used to create blocking OS queues of arbitrary objects. 'Static' queues are queues for which the underlying memory is allocated statically.

#include "etcpal/cpp/static_queue.h"
struct Foo
{
Foo(int new_value) : value(new_value) {}
int value{0};
};
// Create a queue big enough to hold 15 Foo instances.
An RTOS queue class.
Definition: queue.h:94

Use the Send() and Receive() functions to add items to and remove items from the queue.

queue.Send(Foo(42));
Foo received_foo;
queue.Receive(received_foo);
EXPECT_EQ(received_foo.value, 42);
bool Send(const T &data, int timeout_ms=ETCPAL_WAIT_FOREVER)
Add some data to the queue.
Definition: queue.h:151
bool Receive(T &data, int timeout_ms=ETCPAL_WAIT_FOREVER)
Get an item from the queue.
Definition: queue.h:170

By default, the Send() and Receive() functions will block indefinitely. You can also specify timeouts to these functions:

Foo received_foo;
queue.Receive(received_foo, 50); // Block up to 50 milliseconds waiting for
a Foo queue.Receive(received_foo, 0); // Return immediately if a Foo is not
available queue.Receive(received_foo, ETCPAL_WAIT_FOREVER); // Block
indefinitely waiting for a Foo
// In a C++14 or greater environment...
using namespace std::chrono_literals;
queue.Receive(received_foo, 2s); // Block up to 2 seconds waiting for a Foo
#define ETCPAL_WAIT_FOREVER
For etcpal_ functions that take a millisecond timeout, this means to wait indefinitely.
Definition: common.h:118

In these cases, the Send() and Receive() functions will return false if the timeout was reached while waiting.

OS queues are only available on RTOS platforms. See the queue (RTOS queues) module for details on what platforms this class is available on.

Data Structures

class  StaticQueue< T, N >
 An RTOS queue class. More...