Chris Mason | 6fa70da | 2010-06-11 11:17:59 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_XLIST_H |
| 2 | #define _LINUX_XLIST_H |
| 3 | |
| 4 | #include <linux/stddef.h> |
| 5 | #include <linux/poison.h> |
| 6 | #include <linux/prefetch.h> |
| 7 | #include <asm/system.h> |
| 8 | |
| 9 | struct xlist_head { |
| 10 | struct xlist_head *next; |
| 11 | }; |
| 12 | |
Andy Grover | fbf4d7e | 2010-06-11 16:24:42 -0700 | [diff] [blame] | 13 | static inline void INIT_XLIST_HEAD(struct xlist_head *list) |
| 14 | { |
| 15 | list->next = NULL; |
| 16 | } |
Chris Mason | 6fa70da | 2010-06-11 11:17:59 -0700 | [diff] [blame] | 17 | |
Andy Grover | fbf4d7e | 2010-06-11 16:24:42 -0700 | [diff] [blame] | 18 | static inline int xlist_empty(struct xlist_head *head) |
| 19 | { |
| 20 | return head->next == NULL; |
| 21 | } |
| 22 | |
| 23 | static inline void xlist_add(struct xlist_head *new, struct xlist_head *tail, |
| 24 | struct xlist_head *head) |
Chris Mason | 6fa70da | 2010-06-11 11:17:59 -0700 | [diff] [blame] | 25 | { |
| 26 | struct xlist_head *cur; |
| 27 | struct xlist_head *check; |
| 28 | |
| 29 | while (1) { |
| 30 | cur = head->next; |
| 31 | tail->next = cur; |
| 32 | check = cmpxchg(&head->next, cur, new); |
| 33 | if (check == cur) |
| 34 | break; |
| 35 | } |
| 36 | } |
| 37 | |
Chris Mason | 6fa70da | 2010-06-11 11:17:59 -0700 | [diff] [blame] | 38 | static inline struct xlist_head *xlist_del_head(struct xlist_head *head) |
| 39 | { |
| 40 | struct xlist_head *cur; |
| 41 | struct xlist_head *check; |
| 42 | struct xlist_head *next; |
| 43 | |
| 44 | while (1) { |
| 45 | cur = head->next; |
| 46 | if (!cur) |
| 47 | goto out; |
| 48 | |
Chris Mason | 6fa70da | 2010-06-11 11:17:59 -0700 | [diff] [blame] | 49 | next = cur->next; |
| 50 | check = cmpxchg(&head->next, cur, next); |
| 51 | if (check == cur) |
| 52 | goto out; |
| 53 | } |
| 54 | out: |
| 55 | return cur; |
| 56 | } |
| 57 | |
| 58 | static inline struct xlist_head *xlist_del_head_fast(struct xlist_head *head) |
| 59 | { |
| 60 | struct xlist_head *cur; |
| 61 | |
| 62 | cur = head->next; |
Andy Grover | fbf4d7e | 2010-06-11 16:24:42 -0700 | [diff] [blame] | 63 | if (!cur) |
Chris Mason | 6fa70da | 2010-06-11 11:17:59 -0700 | [diff] [blame] | 64 | return NULL; |
| 65 | |
| 66 | head->next = cur->next; |
| 67 | return cur; |
| 68 | } |
| 69 | |
| 70 | static inline void xlist_splice(struct xlist_head *list, |
| 71 | struct xlist_head *head) |
| 72 | { |
| 73 | struct xlist_head *cur; |
| 74 | |
| 75 | WARN_ON(head->next); |
| 76 | cur = xchg(&list->next, NULL); |
| 77 | head->next = cur; |
| 78 | } |
| 79 | |
Chris Mason | 6fa70da | 2010-06-11 11:17:59 -0700 | [diff] [blame] | 80 | #endif |