kernel 中circle buffer的使用
来源:互联网 发布:一度教育java 编辑:程序博客网 时间:2024/06/05 06:28
kernel 提供下面四个宏用于circ_buf的编程
返回buffer中没有读的count
#define CIRC_CNT(head,tail,size) (((head) - (tail)) & ((size)-1))
返回还有几个空间可以写
#define CIRC_SPACE(head,tail,size) CIRC_CNT((tail),((head)+1),(size))
我们假定size =8,head=6,tail=4.
head-tail = -3 ,计算机中是用反码来表示的。-3的反码是1111 1101 & 0000 0111 = 0000 0101 =5表示还有5个空间可以写.8-4+1刚好等于5.
25 #define CIRC_CNT_TO_END(head,tail,size) \
26 ({int end = (size) - (tail); \
27 int n = ((head) + end) & ((size)-1); \
28 n < end ? n : end;})
从header到size还有几个位置,head =6,tail=4 size=8.则返回2
31 #define CIRC_SPACE_TO_END(head,tail,size) \
32 ({int end = (size) - 1 - (head); \
33 int n = (end + (tail)) & ((size)-1); \
34 n <= end ? n : end+1;})
从tail到size还有几个位置,head =6,tail=4 size=8.则返回5
0 0
- kernel 中circle buffer的使用
- Winpcap的Kernel Buffer和其他的Buffer设置
- 【NIO】dawn中buffer的使用
- Kernel的环形Buffer(Ring Buffer)——以Logger Buffer为例
- linux kernel中timer的使用
- linux kernel中timer的使用
- 查找kernel中使用的ko
- kernel中常用数据结构之kfifo(改造为ring buffer)
- 打开的磁盘文件的FILE结构体及buffer使用的是kernel的地址空间
- 徽章系列4: Circle CI 的使用
- 徽章系列4: Circle CI 的使用
- buffer object 的使用
- Protoc buffer的使用
- protocol buffer的使用
- golang buffer的使用
- Java中使用Protocol Buffer
- Java中使用Protocol Buffer的简单教程
- linux中内存使用,swap,cache,buffer的含义
- poj 2251 Dungeon Master
- 10003木棍切割问题
- php
- Api23及以上不支持Httpclient解决办法
- 每日一linux命令(49)-------ln 命令
- kernel 中circle buffer的使用
- JavaIO知识小结和操作规律
- 七层OSI和四层网络模型
- 杂七杂八的概念
- POJ 1442 Black Box 优先队列 求前a[k]个数中第k大的数
- VS2013未能正确加载的问题
- 7.grep和正则
- 集合中存储时的对象重写比较方法
- JSP——过滤器篇