双链表判断函数
1、判断结点是不是链表head的最后一个结点
/**
* list_is_last - tests whether @list is the last entry in list @head
* @list: the entry to test
* @head: the head of the list
*/
static inline int list_is_last(const struct list_head *list,
const struct list_head *head)
{
return list->next == head;
}
方法很简单:检测 list指向的entry的next结点是否是head,如果是,则返回true,否则,返回false!
用途:对于有序链表,从头遍历链表,需要这样做遍历结束条件
2、判断链表是否为空
/**
* list_empty - tests whether a list is empty
* @head: the list to test.
*/
static inline int list_empty(const struct list_head *head)
{
return head->next == head;
}
有上篇博文可知在链表初始化时,宏定义