5#include "libxr_def.hpp"
48 return CreateNewBlockNoLock();
59 return AppendToCurrentBlockNoLock(data, size);
69 ErrorCode
Pop(
size_t size,
void *data =
nullptr)
73 return PopNoLock(size, data);
90 return ErrorCode::TIMEOUT;
93 return PopNoLock(size, data);
124 return ErrorCode::TIMEOUT;
136 block_queue_.
Reset();
149 return data_queue_.
Size();
162 return block_queue_.
Size();
180 return data_queue_.
Size();
199 return block_queue_.
Size();
304 ErrorCode CreateNewBlockNoLock()
313 return ErrorCode::OK;
317 if (block_queue_.
Size() >= max_blocks_)
319 return ErrorCode::FULL;
325 ErrorCode AppendToCurrentBlockNoLock(
const void *data,
size_t size)
329 return ErrorCode::PTR_NULL;
333 return ErrorCode::ARG_ERR;
336 if (block_queue_.
Size() == 0)
338 if (CreateNewBlockNoLock() != ErrorCode::OK)
340 return ErrorCode::FULL;
350 return ErrorCode::NO_BUFF;
356 return ErrorCode::FULL;
360 return ErrorCode::OK;
363 ErrorCode PopNoLock(
size_t size,
void *data =
nullptr)
365 if (data_queue_.
Size() < size)
367 return ErrorCode::EMPTY;
377 return ErrorCode::CHECK_ERR;
387 return ErrorCode::CHECK_ERR;
398 return ErrorCode::CHECK_ERR;
406 return ErrorCode::OK;
418 return ErrorCode::EMPTY;
423 return ErrorCode::EMPTY;
427 if (block_queue_.
Pop(&
block) != ErrorCode::OK)
430 return ErrorCode::EMPTY;
436 return ErrorCode::CHECK_ERR;
439 return ErrorCode::OK;
442 BaseQueue block_queue_;
443 BaseQueue data_queue_;
ErrorCode Pop(void *data=nullptr)
移除队列头部的元素 (Pop the front element from the queue).
ErrorCode Push(const void *data)
向队列中添加一个元素 (Push an element into the queue).
size_t Size()
获取队列中的元素个数 (Get the number of elements in the queue).
ErrorCode PopBatch(void *data, size_t size)
批量移除多个元素 (Pop multiple elements from the queue).
void Reset()
重置队列,清空所有数据 (Reset the queue and clear all data).
int GetFirstElementIndex()
获取队列中第一个元素的索引 (Get the index of the first element in the queue).
size_t EmptySize()
获取队列的空闲空间 (Get the available space in the queue).
ErrorCode PushBatch(const void *data, size_t size)
批量推入多个元素 (Push multiple elements into the queue).
int GetLastElementIndex()
获取队列中最后一个元素的索引 (Get the index of the last element in the queue).
块队列(ChunkQueue)用于存储和管理数据块 ChunkQueue is used to store and manage chunks of data
size_t BlockSize()
获取当前数据块数量 Gets the current number of data blocks
size_t SizeFromCallback(bool in_isr)
从 ISR 中获取当前数据大小 Gets the current data size from an ISR
ErrorCode AppendToCurrentBlock(const void *data, size_t size)
创建一个新的数据块(线程安全) Creates a new data block (thread-safe)
size_t EmptySize()
获取队列的剩余可用空间(线程安全) Gets the remaining available space in the queue (thread-safe)
size_t EmptyBlockSizeFromCallback(bool in_isr)
从 ISR(中断服务例程)中获取块信息的剩余可用空间 Gets the remaining available space in the block information from an ISR (I...
ErrorCode CreateNewBlock()
创建一个新的数据块(线程安全) Creates a new data block (thread-safe)
ErrorCode PopBlockFromCallback(void *buffer, size_t *out_size, bool in_isr)
从回调函数(ISR)中弹出整个数据块 Pops an entire data block from an ISR
ErrorCode PopFromCallback(size_t size, void *data, bool in_isr)
从回调函数(ISR)中弹出数据 Pops data from an ISR (Interrupt Service Routine)
ErrorCode Pop(size_t size, void *data=nullptr)
弹出指定大小的数据(线程安全) Pops the specified size of data (thread-safe)
size_t EmptySizeFromCallback(bool in_isr)
从 ISR(中断服务例程)中获取队列的剩余可用空间 Gets the remaining available space in the queue from an ISR (Interrupt Serv...
size_t Size()
获取当前数据大小 Gets the current size of the data
ChunkQueue(size_t max_blocks, size_t data_buffer_size)
构造一个块队列 Constructs a chunk queue
size_t BlockSizeFromCallback(bool in_isr)
从 ISR 中获取当前数据块数量 Gets the current number of data blocks from an ISR
size_t EmptyBlockSize()
获取块信息的剩余可用空间(线程安全) Gets the remaining available space in the block information (thread-safe)
void Reset()
重置队列 Resets the queue
uint32_t BlockInfo
记录块信息的类型 Type for storing block information
ErrorCode PopBlock(void *buffer, size_t *out_size)
弹出整个数据块(线程安全) Pops an entire data block (thread-safe)
互斥锁的 RAII 机制封装 (RAII-style mechanism for automatic mutex management).
回调(ISR)上下文中的互斥锁管理类 (Lock management class for ISR context).
LibXR Color Control Library / LibXR终端颜色控制库
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值