1、环形缓冲区
一种数据结构,适用于固定的缓冲区大小、数据先进先出的场合。
所谓环形,是指用完最后一个数据再用第一个数据,首尾相连。
- 两个指针:读偏移地址、写偏移地址;
- 一个整型:计数数据量,用于检测缓冲区是满或空;
2、邮箱中的环形缓冲区的操作
2.1、邮箱结构体
邮箱结构体中,entry就是邮箱中的数据量,in_offset是写邮箱的偏移地址,out_offset是读邮箱的偏移地址;
struct rt_mailbox
{
struct rt_ipc_object parent; /**< inherit from ipc_object */
rt_ubase_t *msg_pool; /**< start address of message buffer */
rt_uint16_t size; /**< size of message pool */
rt_uint16_t entry; /**< number of messages in msg_pool */
rt_uint16_t in_offset; /**< input offset of the message buffer */
rt_uint16_t out_offset; /**< output offset of the message buffer */
rt_list_t suspend_sender_thread; /**< sender thread suspended on this mailbox */
};