1
2
3
4
5#ifndef _LINUX_CIRC_BUF_H
6#define _LINUX_CIRC_BUF_H 1
7
8struct circ_buf {
9 char *buf;
10 int head;
11 int tail;
12};
13
14
15#define CIRC_CNT(head,tail,size) (((head) - (tail)) & ((size)-1))
16
17
18
19
20#define CIRC_SPACE(head,tail,size) CIRC_CNT((tail),((head)+1),(size))
21
22
23
24
25#define CIRC_CNT_TO_END(head,tail,size) \
26 ({int end = (size) - (tail); \
27 int n = ((head) + end) & ((size)-1); \
28 n < end ? n : end;})
29
30
31#define CIRC_SPACE_TO_END(head,tail,size) \
32 ({int end = (size) - 1 - (head); \
33 int n = (end + (tail)) & ((size)-1); \
34 n <= end ? n : end+1;})
35
36#endif
37