[PATCH] bcm43xx: Fix array overrun in bcm43xx_geo_init
[linux-2.6/kmemtrace.git] / include / linux / circ_buf.h
bloba2ed0591fb19c57f5544f74f6233afe7cda60d35
1 #ifndef _LINUX_CIRC_BUF_H
2 #define _LINUX_CIRC_BUF_H 1
4 struct circ_buf {
5 char *buf;
6 int head;
7 int tail;
8 };
10 /* Return count in buffer. */
11 #define CIRC_CNT(head,tail,size) (((head) - (tail)) & ((size)-1))
13 /* Return space available, 0..size-1. We always leave one free char
14 as a completely full buffer has head == tail, which is the same as
15 empty. */
16 #define CIRC_SPACE(head,tail,size) CIRC_CNT((tail),((head)+1),(size))
18 /* Return count up to the end of the buffer. Carefully avoid
19 accessing head and tail more than once, so they can change
20 underneath us without returning inconsistent results. */
21 #define CIRC_CNT_TO_END(head,tail,size) \
22 ({int end = (size) - (tail); \
23 int n = ((head) + end) & ((size)-1); \
24 n < end ? n : end;})
26 /* Return space available up to the end of the buffer. */
27 #define CIRC_SPACE_TO_END(head,tail,size) \
28 ({int end = (size) - 1 - (head); \
29 int n = (end + (tail)) & ((size)-1); \
30 n <= end ? n : end+1;})
32 #endif /* _LINUX_CIRC_BUF_H */