当前位置: 技术问答>linux和unix
list.h中删除元素函数的一段代码
来源: 互联网 发布时间:2017-04-22
本文导语: #ifndef CONFIG_DEBUG_LIST static inline void list_del(struct list_head *entry) { __list_del(entry->prev, entry->next); entry->next = LIST_POISON1; entry->prev = LIST_POISON2; } #else extern void list_del(struct list_head *entry); #endif 查看下LIST_POISON1的定义: #define...
#ifndef CONFIG_DEBUG_LIST
static inline void list_del(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
entry->next = LIST_POISON1;
entry->prev = LIST_POISON2;
}
#else
extern void list_del(struct list_head *entry);
#endif
查看下LIST_POISON1的定义:
#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
再查看下POISON_POINTER_DELTA:
#ifdef CONFIG_ILLEGAL_POINTER_VALUE
# define POISON_POINTER_DELTA _AC(CONFIG_ILLEGAL_POINTER_VALUE, UL)
#else
# define POISON_POINTER_DELTA 0
#endif
entry->next到底指向哪了?这与entry->next=NULL是否效果相同?
|
参考http://blog.csdn.net/mznewfacer/article/details/7312313
如果链表里有节点,非空不会一直成立
static inline int list_empty(const struct list_head *head)
{
return head->next == head;
}
如果链表里有节点,非空不会一直成立
static inline int list_empty(const struct list_head *head)
{
return head->next == head;
}
|
/*
18 * These are non-NULL pointers that will result in page faults
19 * under normal circumstances, used to verify that nobody uses
20 * non-initialized list entries.
21 */
22 #define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
23 #define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
以上是官方解释
LIST_POISON就是一段无效的地址区,当开发者误用到这个地址时,会发出页错误。
18 * These are non-NULL pointers that will result in page faults
19 * under normal circumstances, used to verify that nobody uses
20 * non-initialized list entries.
21 */
22 #define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
23 #define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
以上是官方解释
LIST_POISON就是一段无效的地址区,当开发者误用到这个地址时,会发出页错误。