内核链表模板【全部在头文件实现,我是第一次看到这种形式】
#ifndef __DLIST_H
#define __DLIST_H
/* This file is from Linux Kernel (include/linux/list.h)
* and modified by simply removing hardware prefetching of list items.
* Here by copyright, credits attributed to wherever they belong.
* Kulesh Shanmugasundaram (kulesh [squiggly] isis.poly.edu)
*/
//此文件是从Linux内核(包括/ Linux /列表。H)通过简单的移除列表项的硬件预取改性。在著作权,不论他们属于学分归因于Kulesh Shanmugasundaram*/
/*Simple doubly linked list implementation. 简单的双链表的实现
* Some of the internal functions(一些内部功能
) (“__xxx”) are useful when
* manipulating whole lists rather than single entries(操纵整个列表,而不是单一的条目
), as
* sometimes we already know the next/prev entries(下/上的条目
) and we can
* generate better code by using them directly rather than
* using the generic single-entry routines. 我们可以产生更好的代码直接使用它们而不是使用通用的单一入口例程
*/
/**
* container_of - cast a member of a structure out to the containing structure
* container_of铸造结构的成员的容置结构
* @ptr: the pointer to the member.
* @type: the type of the container struct this is embedded in.
* @member: the name of the member within the struct.
*
*/
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
/*
* These are non-NULL pointers that will result in page faults
* under normal circumstances, used to verify that nobody uses
* non-initialized list entries. 这些都是非空指针,将导致页错误
在正常情况下,用来验证没人用的未初始化列表条目。
*/
#define LIST_POISON1 ((void *) 0x00100100)
#define LIST_POISON2 ((void *) 0x00200)
struct list_head {
struct list_head *next, *prev;
};
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
#define INIT_LIST_HEAD(ptr) do { \
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)
/*
* Insert a new entry between two known consecutive entries.
*
* This is only for int