aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/circ_buf.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/linux/circ_buf.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
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 */