5#ifndef UTILS_THREAD_SAFE_QUEUE_H
6#define UTILS_THREAD_SAFE_QUEUE_H
10#include <etl/optional.h>
13#include "src/system/hal/mutex.h"
49 etl::optional<T>
pop()
54 etl::optional<T> item(_queue.front());
74 static constexpr size_t capacity() {
return N; }
81 ~Lock() { hal::mutex::hal_mutex_unlock(&_m); }
82 Lock(
const Lock&) =
delete;
83 Lock& operator=(
const Lock&) =
delete;
86 hal::mutex::hal_mutex_t& _m;
89 etl::queue<T, N> _queue;
90 hal::mutex::hal_mutex_t _mutex;
Fixed capacity FIFO queue, guarded by a mutex. Push and pop can be called from any thread,...
Definition: thread_safe_queue.h:24
static constexpr size_t capacity()
Maximum number of stored items.
Definition: thread_safe_queue.h:74
bool push(const T &item)
Push an item at the end of the queue.
Definition: thread_safe_queue.h:35
void clear()
Drop all stored items.
Definition: thread_safe_queue.h:67
size_t size()
Return the number of stored items.
Definition: thread_safe_queue.h:60
etl::optional< T > pop()
Pop the oldest item.
Definition: thread_safe_queue.h:49
Program scope.
Definition: control_fixed_modes.hpp:14