esp8266ndn
NDN Arduino library for ESP8266 and more
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
queue-freertos.hpp
Go to the documentation of this file.
1#ifndef ESP8266NDN_PORT_QUEUE_FREERTOS_HPP
2#define ESP8266NDN_PORT_QUEUE_FREERTOS_HPP
3
4#include "choose.h"
5
6#include <cstdlib>
7#include <tuple>
8
9#if defined(ARDUINO_ARCH_RP2040)
10#include <Arduino.h> // https://github.com/earlephilhower/arduino-pico/issues/2287
11#include <FreeRTOS.h>
12#include <queue.h>
13#else
14#include <freertos/FreeRTOS.h>
15#include <freertos/queue.h>
16#endif
17
18namespace esp8266ndn {
19namespace ndnph_port_freertos {
20
22template<typename T, size_t capacity>
23class SafeQueue {
24public:
25 using Item = T;
26 static_assert(std::is_trivially_copyable<Item>::value, "");
27 static_assert(std::is_trivially_destructible<Item>::value, "");
28
30 m_queue = xQueueCreate(capacity, sizeof(Item));
31 }
32
34 vQueueDelete(m_queue);
35 }
36
37 bool push(Item item) {
38 BaseType_t res = xQueueSendToBack(m_queue, &item, 0);
39 return res == pdTRUE;
40 }
41
42 std::tuple<Item, bool> pop() {
43 Item item;
44 BaseType_t res = xQueueReceive(m_queue, &item, 0);
45 return std::make_tuple(std::move(item), res == pdTRUE);
46 }
47
48private:
49 QueueHandle_t m_queue;
50};
51
52} // namespace ndnph_port_freertos
53} // namespace esp8266ndn
54
55#ifdef ESP8266NDN_PORT_QUEUE_FREERTOS
56namespace ndnph {
57namespace port {
58template<typename T, size_t capacity>
60} // namespace port
61} // namespace ndnph
62#endif // ESP8266NDN_PORT_QUEUE_FREERTOS
63
64#endif // ESP8266NDN_PORT_QUEUE_FREERTOS_HPP
Generic thread-safe queue, implemented with FreeRTOS queue API.
Definition queue-freertos.hpp:23
~SafeQueue()
Definition queue-freertos.hpp:33
T Item
Definition queue-freertos.hpp:25
SafeQueue()
Definition queue-freertos.hpp:29
bool push(Item item)
Definition queue-freertos.hpp:37
std::tuple< Item, bool > pop()
Definition queue-freertos.hpp:42
Definition autoconfig.hpp:24
Definition fs.hpp:33