linux 队列用法
来源:互联网 发布:西门子plc编程技巧 编辑:程序博客网 时间:2024/05/22 16:38
最近没事总结一下linux中队列的用法和自己在代码中遇到的
1. 在队列应用中主要有如下用途:
1. 首先结构体的 定义
typedef struct _List_Head
{
struct _List_Head *prev, *next;
} List_Head, *PList_Head;
#define __List_Add(new_one_,prev_,next_)
({
(next_)->prev = (new_one_); \
(new_one_)->next = (next_); \
(new_one_)->prev = (prev_); \
(prev_)->next = (new_one_); \
})
在队列头添加一个元素:
#define List_Add(new_one, head) \
({ \
register List_Head *a = ((head)->next);\
__List_Add((new_one), (head), a); \
})
在队列尾添加一个元素:
#define List_AddTail(new_one, head) \
({ \
register List_Head *a = ((head)->prev);\
__List_Add((new_one), a, (head)); \
})
在队列中删除一个元素:
#define __List_Del( prev_, next_) \
({ \
(next_)->prev = (prev_); \
(prev_)->next = (next_); \
})
#define List_Del(entry) \
({ \
__List_Del(((entry)->prev), ((entry)->next)); \
(entry)->next = (entry)->prev = NULL; \
})
判断队列是否为空:
#define List_Empty(head) (((head)->next)==(head))
队列的遍历:
#define LIST_ENTRY(ptr, type, member) \
CONTAINER_OF(ptr, type, member)
static MV_INLINE List_Head *List_GetFirst(List_Head * head)
{
List_Head *one = NULL;
if (List_Empty(head))
return NULL;
one = head->next;
List_Del(one);
return one;
}
#define List_GetFirstEntry(head, type, member) \
LIST_ENTRY(List_GetFirst(head), type, member)
计算对联的长度:
#define List_GetCount(head) \
({ \
register List_Head *pos; \
register int i=0; \
LIST_FOR_EACH(pos, head) { \
i++; \
} \
(i); \
})
- linux 队列用法
- linux消息队列用法实例
- Linux内核中等待队列的几种用法
- Linux内核中等待队列的几种用法
- Linux内核中等待队列的几种用法
- Linux内核中等待队列的几种用法
- Linux内核中等待队列的几种用法
- Linux内核中等待队列的几种用法
- Linux内核中等待队列的几种用法_zzhere2007
- Linux内核中等待队列的几种用法
- Linux内核中等待队列的几种用法
- linux 队列
- 优先队列的用法
- 优先队列的用法
- 优先队列用法
- 优先队列用法
- 优先队列的用法
- 优先队列用法
- C++ primer学习随记
- Java基础-网络编程(自定义图形界面浏览器-Tomcat服务端)
- HT全矢量化的图形组件设计
- 排名问题
- C++ primer(第五版) 练习 4.21 个人code
- linux 队列用法
- MFC多线程编程之四——线程的同步
- Java基础加强-eclipse开发工具
- windows OS右键-新建中添加C语言源文件
- bzoj1632 [Usaco2007 Feb]Lilypad Pond
- hdoj 1040 As Easy As A+B
- Java基础加强-JDK 5.0 新特性
- Android开发-android架构
- Java基础加强-java5的枚举