aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/circ_buf.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/circ_buf.h')
-rw-r--r--include/linux/circ_buf.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/include/linux/circ_buf.h b/include/linux/circ_buf.h
new file mode 100644
index 000000000000..a2ed0591fb19
--- /dev/null
+++ b/include/linux/circ_buf.h
@@ -0,0 +1,32 @@
1#ifndef _LINUX_CIRC_BUF_H
2#define _LINUX_CIRC_BUF_H 1
3
4struct circ_buf {
5 char *buf;
6 int head;
7 int tail;
8};
9
10/* Return count in buffer. */
11#define CIRC_CNT(head,tail,size) (((head) - (tail)) & ((size)-1))
12
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))
17
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;})
25
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;})
31
32#endif /* _LINUX_CIRC_BUF_H */