EtcPal  0.4.1
ETC Platform Abstraction Layer (EtcPal)
View other versions:
queue (RTOS queues)

Overview

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

Provides a template class Queue which can be used to create blocking OS queues of arbitrary objects.

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
C++ wrapper and utilities for etcpal/queue.h.

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);

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:111

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  Queue< T >
 An RTOS queue class. More...