2 #include "AudioTools/CoreAudio/AudioBasic/Collections/Allocator.h"
3 #include "AudioConfig.h"
6 # include <freertos/queue.h>
7 # include "freertos/FreeRTOS.h"
27 QueueRTOS(
int size, TickType_t writeMaxWait = portMAX_DELAY,
28 TickType_t readMaxWait = portMAX_DELAY,
29 Allocator& allocator = DefaultAllocator) {
31 p_allocator = &allocator;
32 read_max_wait = readMaxWait;
33 write_max_wait = writeMaxWait;
43 void setReadMaxWait(TickType_t ticks) { read_max_wait = ticks; }
45 void setWriteMaxWait(TickType_t ticks) { write_max_wait = ticks; }
51 if (size != queue_size) {
59 bool enqueue(T& data) {
61 if (xQueue==
nullptr)
return false;
62 return xQueueSend(xQueue, (
void*)&data, (TickType_t)write_max_wait);
67 if (xQueue==
nullptr)
return false;
68 return xQueuePeek(xQueue, &data, (TickType_t)read_max_wait);
71 bool dequeue(T& data) {
73 if (xQueue==
nullptr)
return false;
74 return xQueueReceive(xQueue, &data, (TickType_t)read_max_wait);
77 size_t size() {
return queue_size; }
81 if (xQueue==
nullptr)
return false;
86 bool empty() {
return size() == 0; }
89 QueueHandle_t xQueue =
nullptr;
90 TickType_t write_max_wait = portMAX_DELAY;
91 TickType_t read_max_wait = portMAX_DELAY;
92 Allocator* p_allocator =
nullptr;
94 uint8_t* p_data =
nullptr;
95 StaticQueue_t queue_buffer;
99 #if configSUPPORT_STATIC_ALLOCATION
100 p_data = (uint8_t*)p_allocator->allocate((queue_size + 1) *
sizeof(T));
101 if (p_data ==
nullptr)
return false;
102 xQueue = xQueueCreateStatic(queue_size,
sizeof(T), p_data, &queue_buffer);
104 xQueue = xQueueCreate(queue_size,
sizeof(T));
106 if (xQueue ==
nullptr)
return false;
112 if (xQueue !=
nullptr) vQueueDelete(xQueue);
113 if (p_data !=
nullptr) p_allocator->free(p_data);