static inline void __list_add(struct list_head *new, // 要插入的节点
struct list_head *prev,// 前节点 before struct list_head *next) // 后节点 after{
next->prev = new; // 后节点的上家为new
new->next = next;
new->prev = prev;
prev->next = new;
}
static inline void list_add(struct list_head *new, struct list_head *head){
__list_add(new, head, head->next);
}
应该是两种形态:
这个是一个习惯,你在封装的时候,一般给调用者,或者说用户态,看到的接口,只会是简单的逻辑处理,然后调用实现。
而实现的函数,可能是封装在其他地方或库,实现的地方,也可以由其他人单独编码,用户态接口直接调用即可
inline关键字把函数声明为一个内联函数,
编译时,在调用处将函数展开,减少了调用函数时进栈和出栈的次数,坏处是会增加代码段的大小(增加了编译后的二进制文件的大小),
为了提高运行的速度,对于一些程序代码小,运行时间短但利用次数比较多的函数我们就定义为inline,提高程序运行速度。