diff options
author | Hans Petter Selasky <hselasky@FreeBSD.org> | 2016-12-26 10:41:51 +0000 |
---|---|---|
committer | Hans Petter Selasky <hselasky@FreeBSD.org> | 2016-12-26 10:41:51 +0000 |
commit | a11bac7379aa0b0ca4f1c0c85f0cc68c0fe2b126 (patch) | |
tree | f9e62ab33d39da32015645debc2cd8031c8f1a7f /sys | |
parent | 0077de5654d614878342bdb598d2ddb8d0243bb7 (diff) |
Implement more list header file functions.
Add definition guard for the list_head structure.
Obtained from: kmacy @
MFC after: 1 week
Sponsored by: Mellanox Technologies
Notes
Notes:
svn path=/head/; revision=310589
Diffstat (limited to 'sys')
-rw-r--r-- | sys/compat/linuxkpi/common/include/linux/list.h | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/list.h b/sys/compat/linuxkpi/common/include/linux/list.h index fff524338576..d73cbcb73392 100644 --- a/sys/compat/linuxkpi/common/include/linux/list.h +++ b/sys/compat/linuxkpi/common/include/linux/list.h @@ -72,10 +72,18 @@ #define prefetch(x) +#define LINUX_LIST_HEAD_INIT(name) { &(name), &(name) } + +#define LINUX_LIST_HEAD(name) \ + struct list_head name = LINUX_LIST_HEAD_INIT(name) + +#ifndef LIST_HEAD_DEF +#define LIST_HEAD_DEF struct list_head { struct list_head *next; struct list_head *prev; }; +#endif static inline void INIT_LIST_HEAD(struct list_head *list) @@ -91,12 +99,26 @@ list_empty(const struct list_head *head) return (head->next == head); } +static inline int +list_empty_careful(const struct list_head *head) +{ + struct list_head *next = head->next; + + return ((next == head) && (next == head->prev)); +} + +static inline void +__list_del(struct list_head *prev, struct list_head *next) +{ + next->prev = prev; + WRITE_ONCE(prev->next, next); +} + static inline void list_del(struct list_head *entry) { - entry->next->prev = entry->prev; - entry->prev->next = entry->next; + __list_del(entry->prev, entry->next); } static inline void @@ -183,6 +205,11 @@ list_del_init(struct list_head *entry) for (p = list_entry((h)->prev, typeof(*p), field); &(p)->field != (h); \ p = list_entry((p)->field.prev, typeof(*p), field)) +#define list_for_each_entry_safe_reverse(p, n, h, field) \ + for (p = list_entry((h)->prev, typeof(*p), field), \ + n = list_entry((p)->field.prev, typeof(*p), field); &(p)->field != (h); \ + p = n, n = list_entry(n->field.prev, typeof(*n), field)) + #define list_for_each_entry_continue_reverse(p, h, field) \ for (p = list_entry((p)->field.prev, typeof(*p), field); &(p)->field != (h); \ p = list_entry((p)->field.prev, typeof(*p), field)) |