circbuf.h

来自「如文件名」· C头文件 代码 · 共 26 行

H
26
字号
/* 256 Byte circular buffer implementation 
 * Done by David Wolpoff 
 * Last Modified 1 July 2006*/

#define BUF_SIZE 256
#define HEADTOTAIL(x) ( ((x->head - x->tail)<0) ? x->head-x->tail+BUF_SIZE : x->head-x->tail)

typedef struct
{
  int  head;
  int  tail;
  unsigned int circle[BUF_SIZE];
} buf_type;

void init_buffer(volatile buf_type* buffer);

/* returns 0 on success, -1 on fail to insert */
int bufinsert(volatile buf_type* buffer, unsigned int data);

/* Always returns something. */
unsigned int bufextract(volatile buf_type* buffer);

/* Number of occupied spaces in buffer */
int bufused(volatile buf_type* buffer);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?