1#ifndef SENSESP_SYSTEM_TASK_QUEUE_PRODUCER_H_
2#define SENSESP_SYSTEM_TASK_QUEUE_PRODUCER_H_
23 xSemaphoreCreateCounting(std::numeric_limits<int>::max(), 0);
27 void push(
const T& value) {
29 std::queue<T>::push(value);
34 bool pop(T& value,
unsigned int max_duration_ms) {
36 max_duration_ms / portTICK_PERIOD_MS) == pdTRUE) {
38 value = std::queue<T>::front();
48 bool result = std::queue<T>::empty();
55 size_t result = std::queue<T>::size();
83 std::shared_ptr<reactesp::EventLoop> consumer_event_loop,
84 unsigned int poll_rate = 990)
86 auto func = [
this]() {
88 while (queue_.pop(value, 0)) {
95 consumer_event_loop->onTick(func);
97 consumer_event_loop->onRepeatMicros(poll_rate, func);
104 virtual void set(
const T& value)
override { queue_.push(value); }
118 bool wait(T& value,
unsigned int max_duration_ms) {
120 bool result = queue_.pop(received_value, max_duration_ms);
122 value = received_value;
A value container that notifies its observers if it gets changed.
Thread-safe queue for inter-task communication. Works like std::queue.
bool pop(T &value, unsigned int max_duration_ms)
void push(const T &value)
SemaphoreHandle_t queue_semaphore_
SemaphoreHandle_t write_lock_
Producer class that works across task boundaries.
TaskQueueProducer(const T &value, unsigned int poll_rate=990)
TaskQueueProducer(const T &value, std::shared_ptr< reactesp::EventLoop > consumer_event_loop, unsigned int poll_rate=990)
bool wait(T &value, unsigned int max_duration_ms)
Wait for a value to be available in the queue.
virtual void set(const T &value) override
void emit(const T &new_value)
std::shared_ptr< reactesp::EventLoop > event_loop()