| Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame^] | 1 | |
| 2 | #ifndef _LINUX_CIRC_BUF_H |
| 3 | #define _LINUX_CIRC_BUF_H 1 |
| 4 | |
| 5 | struct circ_buf { |
| 6 | char *buf; |
| 7 | int head; |
| 8 | int tail; |
| 9 | }; |
| 10 | |
| 11 | #define CIRC_CNT(head,tail,size) (((head) - (tail)) & ((size)-1)) |
| 12 | |
| 13 | #define CIRC_SPACE(head,tail,size) CIRC_CNT((tail),((head)+1),(size)) |
| 14 | |
| 15 | #define CIRC_CNT_TO_END(head,tail,size) \ |
| 16 | ({int end = (size) - (tail); \ |
| 17 | int n = ((head) + end) & ((size)-1); \ |
| 18 | n < end ? n : end;}) |
| 19 | |
| 20 | #define CIRC_SPACE_TO_END(head,tail,size) \ |
| 21 | ({int end = (size) - 1 - (head); \ |
| 22 | int n = (end + (tail)) & ((size)-1); \ |
| 23 | n <= end ? n : end+1;}) |
| 24 | |
| 25 | #endif |