3.1、環形緩衝區初始化
int ringbufferinit(ringbuffer_t *ringbuf)
3.2、判斷環形緩衝區為空
int isringbufferempty(ringbuffer_t *ringbuf)
3.3、判斷環形緩衝區為滿
int isringbufferfull(ringbuffer_t *ringbuf)
3.4、向環形緩衝區寫入長度為buffer_len位元組的資料
int ringbufferproduce(ringbuffer_t *ringbuf,char *buffer,int buffer_len)
3.5、從環形緩衝區中取出長度為buffer_len長度的資料
int ringbufferconsum(ringbuffer_t *ringbuf,char *buffer,int buffer_len)
3.6、計算環形緩衝區有效資料的長度
int ringbufferlength(ringbuffer_t *ringbuf)
3.7、計算環形緩衝區剩餘空間的長度
int ringbufferfreespace(ringbuffer_t *ringbuf)
標頭檔案
#ifndef _ringbuffer_h
#define _ringbuffer_h
#define max_buffer_len 1024
typedef enum;
typedef struct _ring_buf_ringbuffer_t;
int ringbufferinit(ringbuffer_t *ringbuf);
int isringbufferfull(ringbuffer_t *ringbuf);
int isringbufferempty(ringbuffer_t *ringbuf);
int ringbufferlength(ringbuffer_t *ringbuf);
int ringbufferfreespace(ringbuffer_t *ringbuf);
int ringbufferproduce(ringbuffer_t *ringbuf,char *buffer,int buffer_len);
int ringbufferconsum(ringbuffer_t *ringbuf,char *buffer,int buffer_len);
#endif
測試**
#include #include #include #include #include #include #include "ringbuffer.h"
typedef structmem_data_t;
int main(int arcv,char *ar**)
shmid = shmget(key,4096,0666|ipc_creat);
if(shmid < 0)
data = shmat(shmid,null,0);
if(null == data)
printf("key:%x,shmid:%d,addr:%p\r\n",key,shmid,data);
if(0 == strncmp(ar**[1],"read",4))//出隊
sleep(1);
} }else
while(1)
}ret = shmctl(shmid,0,ipc_rmid);//刪除共享記憶體
if(ret<0)
return 0;
}
c 環形緩衝區
public class circularbuffer icollection,ienumerable,icollection,ienumerable public circularbuffer int capacity,bool allowoverflow public bool allowove...
環形緩衝區
include include include include include define buffsize 1024 1024 define min x,y x y x y pthread mutex t lock pthread mutex initializer struct cycle b...
環形緩衝區
define print buf size 16 1024 static char g pcnetprintbuf 環形緩衝區的首位址 static int g ireadpos 0 環形緩衝區讀的位置 static int g iwritepos 0 環形緩衝區寫的位置 intinit 判斷環形緩...