![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 /* 0003 * See Documentation/core-api/circular-buffers.rst for more information. 0004 */ 0005 0006 #ifndef _LINUX_CIRC_BUF_H 0007 #define _LINUX_CIRC_BUF_H 1 0008 0009 struct circ_buf { 0010 char *buf; 0011 int head; 0012 int tail; 0013 }; 0014 0015 /* Return count in buffer. */ 0016 #define CIRC_CNT(head,tail,size) (((head) - (tail)) & ((size)-1)) 0017 0018 /* Return space available, 0..size-1. We always leave one free char 0019 as a completely full buffer has head == tail, which is the same as 0020 empty. */ 0021 #define CIRC_SPACE(head,tail,size) CIRC_CNT((tail),((head)+1),(size)) 0022 0023 /* Return count up to the end of the buffer. Carefully avoid 0024 accessing head and tail more than once, so they can change 0025 underneath us without returning inconsistent results. */ 0026 #define CIRC_CNT_TO_END(head,tail,size) \ 0027 ({int end = (size) - (tail); \ 0028 int n = ((head) + end) & ((size)-1); \ 0029 n < end ? n : end;}) 0030 0031 /* Return space available up to the end of the buffer. */ 0032 #define CIRC_SPACE_TO_END(head,tail,size) \ 0033 ({int end = (size) - 1 - (head); \ 0034 int n = (end + (tail)) & ((size)-1); \ 0035 n <= end ? n : end+1;}) 0036 0037 #endif /* _LINUX_CIRC_BUF_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |