esp8266ndn
NDN Arduino library for ESP8266 and more
Loading...
Searching...
No Matches
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#include <freertos/FreeRTOS.h>
10#include <freertos/queue.h>
11
12namespace esp8266ndn {
13namespace ndnph_port_freertos {
14
16template<typename T, size_t capacity>
17class SafeQueue {
18public:
19 using Item = T;
20 static_assert(std::is_trivially_copyable<Item>::value, "");
21 static_assert(std::is_trivially_destructible<Item>::value, "");
22
24 m_queue = xQueueCreate(capacity, sizeof(Item));
25 }
26
28 vQueueDelete(m_queue);
29 }
30
31 bool push(Item item) {
32 BaseType_t res = xQueueSendToBack(m_queue, &item, 0);
33 return res == pdTRUE;
34 }
35
36 std::tuple<Item, bool> pop() {
37 Item item;
38 BaseType_t res = xQueueReceive(m_queue, &item, 0);
39 return std::make_tuple(std::move(item), res == pdTRUE);
40 }
41
42private:
43 QueueHandle_t m_queue;
44};
45
46} // namespace ndnph_port_freertos
47} // namespace esp8266ndn
48
49#ifdef ESP8266NDN_PORT_QUEUE_FREERTOS
50namespace ndnph {
51namespace port {
52template<typename T, size_t capacity>
54} // namespace port
55} // namespace ndnph
56#endif // ESP8266NDN_PORT_QUEUE_FREERTOS
57
58#endif // ESP8266NDN_PORT_QUEUE_FREERTOS_HPP
Generic thread-safe queue, implemented with FreeRTOS queue API.
Definition queue-freertos.hpp:17
~SafeQueue()
Definition queue-freertos.hpp:27
T Item
Definition queue-freertos.hpp:19
SafeQueue()
Definition queue-freertos.hpp:23
bool push(Item item)
Definition queue-freertos.hpp:31
std::tuple< Item, bool > pop()
Definition queue-freertos.hpp:36
Definition autoconfig.hpp:24
Definition fs.hpp:33