libxr 1.0
Want to be the best embedded framework
|
块队列(ChunkQueue)用于存储和管理数据块 ChunkQueue is used to store and manage chunks of data More...
#include <chunk_queue.hpp>
Public Types | |
typedef uint32_t | BlockInfo |
记录块信息的类型 Type for storing block information | |
Public Member Functions | |
ChunkQueue (size_t max_blocks, size_t data_buffer_size) | |
构造一个块队列 Constructs a chunk queue | |
ErrorCode | CreateNewBlock () |
创建一个新的数据块(线程安全) Creates a new data block (thread-safe) | |
ErrorCode | AppendToCurrentBlock (const void *data, size_t size) |
创建一个新的数据块(线程安全) Creates a new data block (thread-safe) | |
ErrorCode | Pop (size_t size, void *data=nullptr) |
弹出指定大小的数据(线程安全) Pops the specified size of data (thread-safe) | |
ErrorCode | PopFromCallback (size_t size, void *data, bool in_isr) |
从回调函数(ISR)中弹出数据 Pops data from an ISR (Interrupt Service Routine) | |
ErrorCode | PopBlock (void *buffer, size_t *out_size) |
弹出整个数据块(线程安全) Pops an entire data block (thread-safe) | |
ErrorCode | PopBlockFromCallback (void *buffer, size_t *out_size, bool in_isr) |
从回调函数(ISR)中弹出整个数据块 Pops an entire data block from an ISR | |
void | Reset () |
重置队列 Resets the queue | |
size_t | Size () |
获取当前数据大小 Gets the current size of the 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 | |
size_t | BlockSizeFromCallback (bool in_isr) |
从 ISR 中获取当前数据块数量 Gets the current number of data blocks from an ISR | |
size_t | EmptySize () |
获取队列的剩余可用空间(线程安全) Gets the remaining available space in the queue (thread-safe) | |
size_t | EmptyBlockSize () |
获取块信息的剩余可用空间(线程安全) Gets the remaining available space in the block information (thread-safe) | |
size_t | EmptySizeFromCallback (bool in_isr) |
从 ISR(中断服务例程)中获取队列的剩余可用空间 Gets the remaining available space in the queue from an ISR (Interrupt Service Routine) | |
size_t | EmptyBlockSizeFromCallback (bool in_isr) |
从 ISR(中断服务例程)中获取块信息的剩余可用空间 Gets the remaining available space in the block information from an ISR (Interrupt Service Routine) | |
ChunkQueue (const ChunkQueue &)=delete | |
ChunkQueue | operator= (const ChunkQueue &)=delete |
ChunkQueue | operator= (ChunkQueue &)=delete |
ChunkQueue | operator= (const ChunkQueue &&)=delete |
ChunkQueue | operator= (ChunkQueue &&)=delete |
Private Member Functions | |
ErrorCode | CreateNewBlockNoLock () |
ErrorCode | AppendToCurrentBlockNoLock (const void *data, size_t size) |
ErrorCode | PopNoLock (size_t size, void *data=nullptr) |
ErrorCode | PopBlockNoLock (void *buffer, size_t *out_size) |
Private Attributes | |
BaseQueue | block_queue_ |
BaseQueue | data_queue_ |
size_t | max_blocks_ |
Mutex | mutex_ |
块队列(ChunkQueue)用于存储和管理数据块 ChunkQueue is used to store and manage chunks of data
该类实现了一个支持多块数据存储的队列,提供线程安全的访问方式,并支持从 ISR(中断服务例程)中调用。 This class implements a multi-block data storage queue, provides thread-safe access, and supports calls from an ISR (Interrupt Service Routine).
Definition at line 21 of file chunk_queue.hpp.
记录块信息的类型 Type for storing block information
Definition at line 24 of file chunk_queue.hpp.
构造一个块队列 Constructs a chunk queue
max_blocks | 最大块数 Maximum number of blocks |
data_buffer_size | 数据缓冲区大小 Size of the data buffer |
Definition at line 32 of file chunk_queue.hpp.
创建一个新的数据块(线程安全) Creates a new data block (thread-safe)
Definition at line 56 of file chunk_queue.hpp.
|
inlineprivate |
Definition at line 325 of file chunk_queue.hpp.
|
inline |
获取当前数据块数量 Gets the current number of data blocks
Definition at line 158 of file chunk_queue.hpp.
从 ISR 中获取当前数据块数量 Gets the current number of data blocks from an ISR
in_isr | 是否在 ISR 中调用 Whether it is called from an ISR |
Definition at line 190 of file chunk_queue.hpp.
|
inline |
创建一个新的数据块(线程安全) Creates a new data block (thread-safe)
Definition at line 45 of file chunk_queue.hpp.
|
inlineprivate |
Definition at line 304 of file chunk_queue.hpp.
|
inline |
获取块信息的剩余可用空间(线程安全) Gets the remaining available space in the block information (thread-safe)
Definition at line 236 of file chunk_queue.hpp.
从 ISR(中断服务例程)中获取块信息的剩余可用空间 Gets the remaining available space in the block information from an ISR (Interrupt Service Routine)
in_isr | 是否在 ISR 中调用 Whether it is called from an ISR |
Definition at line 285 of file chunk_queue.hpp.
|
inline |
获取队列的剩余可用空间(线程安全) Gets the remaining available space in the queue (thread-safe)
该方法通过互斥锁保证线程安全,检查 block_queue_
是否还有空余块, 若有,则返回 data_queue_
的剩余空间,否则返回 0。
This method ensures thread safety using a mutex lock. It checks whether block_queue_
has available blocks. If available, it returns the remaining space in data_queue_
, otherwise, it returns 0.
Definition at line 216 of file chunk_queue.hpp.
从 ISR(中断服务例程)中获取队列的剩余可用空间 Gets the remaining available space in the queue from an ISR (Interrupt Service Routine)
in_isr | 是否在 ISR 中调用 Whether it is called from an ISR |
该方法在中断服务例程(ISR)中安全使用,通过 Mutex::LockGuardInCallback
进行锁保护。 若 block_queue_
仍有可用块,则返回 data_queue_
的剩余空间,否则返回 0。
This method is safe to use in an ISR (Interrupt Service Routine), protected by Mutex::LockGuardInCallback
. If block_queue_
has available blocks, it returns the remaining space in data_queue_
, otherwise, it returns 0.
Definition at line 258 of file chunk_queue.hpp.
弹出指定大小的数据(线程安全) Pops the specified size of data (thread-safe)
size | 要弹出的数据大小 Size of the data to pop |
data | 存储弹出数据的缓冲区(可选) Buffer to store popped data (optional) |
Definition at line 69 of file chunk_queue.hpp.
弹出整个数据块(线程安全) Pops an entire data block (thread-safe)
buffer | 存储数据的缓冲区 Buffer to store popped data |
out_size | 返回的块大小 Output parameter for block size |
Definition at line 103 of file chunk_queue.hpp.
|
inline |
从回调函数(ISR)中弹出整个数据块 Pops an entire data block from an ISR
buffer | 存储数据的缓冲区 Buffer to store popped data |
out_size | 返回的块大小 Output parameter for block size |
in_isr | 是否在 ISR 中调用 Whether it is called from an ISR |
Definition at line 118 of file chunk_queue.hpp.
Definition at line 409 of file chunk_queue.hpp.
从回调函数(ISR)中弹出数据 Pops data from an ISR (Interrupt Service Routine)
size | 要弹出的数据大小 Size of the data to pop |
data | 存储弹出数据的缓冲区 Buffer to store popped data |
in_isr | 是否在中断服务程序(ISR)中调用 Whether it is called from an ISR |
Definition at line 84 of file chunk_queue.hpp.
Definition at line 363 of file chunk_queue.hpp.
|
inline |
重置队列 Resets the queue
Definition at line 134 of file chunk_queue.hpp.
|
inline |
获取当前数据大小 Gets the current size of the data
Definition at line 145 of file chunk_queue.hpp.
从 ISR 中获取当前数据大小 Gets the current data size from an ISR
in_isr | 是否在 ISR 中调用 Whether it is called from an ISR |
Definition at line 171 of file chunk_queue.hpp.
|
private |
Definition at line 442 of file chunk_queue.hpp.
|
private |
Definition at line 443 of file chunk_queue.hpp.
|
private |
Definition at line 444 of file chunk_queue.hpp.
|
private |
Definition at line 445 of file chunk_queue.hpp.