list.h
#ifndef LISTHHHHHHH
#define LISTHHHHHHH #include "common.h" /* stolen from kernel */ typedef struct list_node {
struct list_node *next;
struct list_node *prev;
} list_node_t; typedef struct list_head {
struct list_node n;
} list_head_t; #define LIST_HEAD_INIT(name) { { &(name.n), &(name.n) } }
#define LIST_NODE_INIT { NULL, NULL } #define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
#define LIST_NODE(name) \
struct list_node name = LIST_NODE_INIT static inline void INIT_LIST_HEAD(struct list_head *list)
{
list->n.next = &list->n;
list->n.prev = &list->n;
} static inline void INIT_LIST_NODE(struct list_node *list)
{
list->next = NULL;
list->prev = NULL;
} #define list_first_entry(head, type, member) \
list_entry((head)->n.next, type, member) static inline bool list_empty(const struct list_head *head)
{
return head->n.next == &head->n;
} static inline bool list_linked(const struct list_node *node)
{
return node->next != NULL;
} #define list_entry(ptr, type, member) \
container_of(ptr, type, member) #define list_for_each(pos, head) \
for (typeof(pos) LOCAL(n) = (pos = (head)->n.next, pos->next); \
pos != &(head)->n; \
pos = LOCAL(n), LOCAL(n) = pos->next) #define list_for_each_entry(pos, head, member) \
for (typeof(pos) LOCAL(n) = (pos = list_entry((head)->n.next, \
typeof(*pos), \
member), \
list_entry(pos->member.next, \
typeof(*pos), \
member)); \
&pos->member != &(head)->n; \
pos = LOCAL(n), LOCAL(n) = list_entry(LOCAL(n)->member.next, \
typeof(*LOCAL(n)), \
member)) static inline void __list_add(struct list_node *new,
struct list_node *prev, struct list_node *next)
{
next->prev = new;
new->next = next;
new->prev = prev;
prev->next = new;
} static inline void list_add(struct list_node *new, struct list_head *head)
{
__list_add(new, &head->n, head->n.next);
} static inline void list_add_tail(struct list_node *new, struct list_head *head)
{
__list_add(new, head->n.prev, &head->n);
} static inline void __list_del(struct list_node *prev, struct list_node *next)
{
next->prev = prev;
prev->next = next;
} static inline void __list_del_entry(struct list_node *entry)
{
__list_del(entry->prev, entry->next);
} static inline void list_del(struct list_node *entry)
{
__list_del(entry->prev, entry->next);
entry->next = entry->prev = NULL;
} static inline void list_move(struct list_node *list, struct list_head *head)
{
__list_del_entry(list);
list_add(list, head);
} static inline void list_move_tail(struct list_node *list,
struct list_head *head)
{
__list_del_entry(list);
list_add_tail(list, head);
} static inline void __list_splice(const struct list_head *list,
struct list_node *prev, struct list_node *next)
{
struct list_node *first = list->n.next;
struct list_node *last = list->n.prev; first->prev = prev;
prev->next = first; last->next = next;
next->prev = last;
} static inline void list_splice_init(struct list_head *list,
struct list_head *head)
{
if (!list_empty(list)) {
__list_splice(list, &head->n, head->n.next);
INIT_LIST_HEAD(list);
}
} static inline void list_splice_tail_init(struct list_head *list,
struct list_head *head)
{
if (!list_empty(list)) {
__list_splice(list, head->n.prev, &head->n);
INIT_LIST_HEAD(list);
}
} #endif
list.h的更多相关文章
- APUE中fcntl.h的使用及O_SYNC在Mac与Ubuntu下的测试
此部分测试涉及到APUE V3中,第三章的图3-12到图3-14. 通过fcntl.h提供的功能,修改fd的文件属性,本处增加O_SYNC功能,并测试其效果. 本文涉及代码: tree ch3 ch3 ...
- 关于apue.3e中apue.h的使用
关于apue.3e中apue.h的使用 近来要学一遍APUE第三版,并于此开博做为记录. 先下载源文件: # url: http://http//www.apuebook.com/code3e.htm ...
- YYModel 源码解读(二)之NSObject+YYModel.h (1)
本篇文章主要介绍 _YYModelPropertyMeta 前边的内容 首先先解释一下前边的辅助函数和枚举变量,在写一个功能的时候,这些辅助的东西可能不是一开始就能想出来的,应该是在后续的编码过程中 ...
- YYModel 源码解读(一)之YYModel.h
#if __has_include(<YYModel/YYModel.h>) FOUNDATION_EXPORT double YYModelVersionNumber; FOUNDATI ...
- error RC1015: cannot open include file 'afxres.h' 解决办法
在为WindowsPhone8程序添加本地化的过程中遇到这个问题: 问题原因就是afxres.h文件缺失,下载它,放到VS安装目录下的VS\include目录下就可以了(选择目录的时候注意对应对版本) ...
- afxcomctl32.h与afxcomctl32.inl报错
afxcomctl32.h与afxcomctl32.inl报错 编译公司一个几年前的老项目,是从VC6.0升级到VS2005的. 1.编译时报缺少头文件,于是附件包含目录,于是出现了以下报错: 1&g ...
- C标准头文件<math.h>
定义域错误可以理解为超出了函数的适用范围,如果发生了定义域错误,设errno为EDOM 如果结果不能表示为double值,则发生值域错误,如果结果上溢,则函数返回HUGE_VAL的值,设errno为E ...
- C标准头文件<ctype.h>
主要包括了一些字符识别和转换函数 字符判断 isalnum() //函数原型 #include<ctype.h> int isalum(int c); 功能:如果输入的字符是字母(alph ...
- xcode中的.h和.m文件分别是什么意思?各有什么用?
.h 表示头文件,用来声明各种成员变量,方法,属性之类的.在import的时候用头文件. .m 主要用来实现.h 里声明的方法.举个例子,如果要写一个方法,你要在.h里先声明: - (void)myM ...
- __dbg.h
#ifndef __HSS_DBG_HSS__ #define __HSS_DBG_HSS__ /*************************************************** ...
随机推荐
- Android框架之网络开发框架Volley
1. Volley简单介绍 我们平时在开发Android应用的时候不可避免地都须要用到网络技术.而多数情况下应用程序都会使用HTTP协议来发送和接收网络数据.Android系统中主要提供了两种方式来进 ...
- Java大数类介绍
java能处理大数的类有两个高精度大整数BigInteger 和高精度浮点数BigDecimal,这两个类位于java.math包内,要使用它们必须在类前面引用该包:import java.math. ...
- codeblocks创建和使用静态库(C语言)
静态库 (扩展名为 .a 或 .lib) 是包含函数的文件,用于在link阶段整合执行程序,动态链接库(扩展名 .dll)是不在link阶段整合进执行程序中的. DLL文件在执行阶段动态调用 下面 ...
- cocos2dx 2.14使用UUID
1首先要清楚objective-c 与c/ c++混编的规则 关于c/c++/obj-c的混合使用 1)obj-c的编译器处理后缀为m的文件时,可以识别obj-c和c的代码,处理mm文件可以识别obj ...
- binary heap
In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...
- 编写跨平台代码之memory alignment
编写网络包(存储在堆上)转换程序时,在hp-ux机器上运行时会遇到 si_code: 1 - BUS_ADRALN - Invalid address alignment. Please refer ...
- App升级时数据库的迁移更新
前一段时间在进行App升级的时候,由于一开始版本初期没有考虑完善,导致走了很多弯路,后来经过自己的一些思考,总结出了一些在app升级的时候,数据库内文件同步保持更新的经验,希望能给大家带来帮助. 总体 ...
- linq按需查询
将不确定变成确定~LINQ查询两种写法,性能没有影响,优化查询应该是“按需查询” 如果在linq中希望进行一对多的复合查询时,请直接在查询中使用join into,或者使用let 关键字,当然在建立实 ...
- SQL打印全年日历
数据库环境:SQL SERVER 2008R2 我之前有写过打印本月日历的SQL,里头有详细的说明.具体请参考前面的博文——生成本月日历. 全年日历只是在本月日历的基础上加了月信息,并按月份分组求得. ...
- 关于通过bindService启动的service,在unbindService后service是否继续运行的讨论
有三种情况:如果直接使用服务,则没有必要进行绑定,但是如果要使用服务里面的方法,则要进行绑定.具体的启动情况有下: 1.当启动时,单独调用bindService方法,在unbindService后,会 ...