# RingBuffer **Repository Path**: onmast/ring-buffer ## Basic Information - **Project Name**: RingBuffer - **Description**: 环形缓冲区 - **Primary Language**: C - **License**: AGPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-01-18 - **Last Updated**: 2024-07-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # RingBuffer #### 介绍 环形缓冲区 #### 使用说明 1. 创建对象 ```C rb_control control; uint32_t testData[50]; ``` 2. 初始化 ```c rb_init(&control,testData,50,sizeof(uint32_t)); ``` 3. 向缓冲区写入数据 ```c // 多线程情况下使用,此处需要加锁 if(rb_is_writeable(&control)){ uint32_t* pData = (uint32_t*)rb_get_write_buf(&control); (*pData) = 0x12345678; }else{ //缓冲区已满,此时不能进行写操作! } // 多线程情况下使用, 此处需要解锁 ``` 4. 从缓冲区读数据 ```c // 多线程情况下使用,此处需要加锁 if(rb_is_readable(&control)){ uint32_t* pData = (uint32_t*)rb_get_read_buf(&control); uint32_t a = (*pData); //a就是从缓冲区中取出的数据。 }else{ //缓冲区为空,此时没有要读的数据 } // 多线程情况下使用,此处需要解锁 ``` #### 其它 1. https://www.airos.net