diff options
Diffstat (limited to 'include/linux/llist.h')
| -rw-r--r-- | include/linux/llist.h | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/include/linux/llist.h b/include/linux/llist.h index aa0c8b5b3cd0..7287734e08d1 100644 --- a/include/linux/llist.h +++ b/include/linux/llist.h | |||
| @@ -35,10 +35,30 @@ | |||
| 35 | * | 35 | * |
| 36 | * The basic atomic operation of this list is cmpxchg on long. On | 36 | * The basic atomic operation of this list is cmpxchg on long. On |
| 37 | * architectures that don't have NMI-safe cmpxchg implementation, the | 37 | * architectures that don't have NMI-safe cmpxchg implementation, the |
| 38 | * list can NOT be used in NMI handler. So code uses the list in NMI | 38 | * list can NOT be used in NMI handlers. So code that uses the list in |
| 39 | * handler should depend on CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG. | 39 | * an NMI handler should depend on CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG. |
| 40 | * | ||
| 41 | * Copyright 2010,2011 Intel Corp. | ||
| 42 | * Author: Huang Ying <ying.huang@intel.com> | ||
| 43 | * | ||
| 44 | * This program is free software; you can redistribute it and/or | ||
| 45 | * modify it under the terms of the GNU General Public License version | ||
| 46 | * 2 as published by the Free Software Foundation; | ||
| 47 | * | ||
| 48 | * This program is distributed in the hope that it will be useful, | ||
| 49 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 50 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 51 | * GNU General Public License for more details. | ||
| 52 | * | ||
| 53 | * You should have received a copy of the GNU General Public License | ||
| 54 | * along with this program; if not, write to the Free Software | ||
| 55 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 40 | */ | 56 | */ |
| 41 | 57 | ||
| 58 | #include <linux/kernel.h> | ||
| 59 | #include <asm/system.h> | ||
| 60 | #include <asm/processor.h> | ||
| 61 | |||
| 42 | struct llist_head { | 62 | struct llist_head { |
| 43 | struct llist_node *first; | 63 | struct llist_node *first; |
| 44 | }; | 64 | }; |
| @@ -113,14 +133,55 @@ static inline void init_llist_head(struct llist_head *list) | |||
| 113 | * test whether the list is empty without deleting something from the | 133 | * test whether the list is empty without deleting something from the |
| 114 | * list. | 134 | * list. |
| 115 | */ | 135 | */ |
| 116 | static inline int llist_empty(const struct llist_head *head) | 136 | static inline bool llist_empty(const struct llist_head *head) |
| 117 | { | 137 | { |
| 118 | return ACCESS_ONCE(head->first) == NULL; | 138 | return ACCESS_ONCE(head->first) == NULL; |
| 119 | } | 139 | } |
| 120 | 140 | ||
| 121 | void llist_add(struct llist_node *new, struct llist_head *head); | 141 | static inline struct llist_node *llist_next(struct llist_node *node) |
| 122 | void llist_add_batch(struct llist_node *new_first, struct llist_node *new_last, | 142 | { |
| 123 | struct llist_head *head); | 143 | return node->next; |
| 124 | struct llist_node *llist_del_first(struct llist_head *head); | 144 | } |
| 125 | struct llist_node *llist_del_all(struct llist_head *head); | 145 | |
| 146 | /** | ||
| 147 | * llist_add - add a new entry | ||
| 148 | * @new: new entry to be added | ||
| 149 | * @head: the head for your lock-less list | ||
| 150 | * | ||
| 151 | * Return whether list is empty before adding. | ||
| 152 | */ | ||
| 153 | static inline bool llist_add(struct llist_node *new, struct llist_head *head) | ||
| 154 | { | ||
| 155 | struct llist_node *entry, *old_entry; | ||
| 156 | |||
| 157 | entry = head->first; | ||
| 158 | for (;;) { | ||
| 159 | old_entry = entry; | ||
| 160 | new->next = entry; | ||
| 161 | entry = cmpxchg(&head->first, old_entry, new); | ||
| 162 | if (entry == old_entry) | ||
| 163 | break; | ||
| 164 | } | ||
| 165 | |||
| 166 | return old_entry == NULL; | ||
| 167 | } | ||
| 168 | |||
| 169 | /** | ||
| 170 | * llist_del_all - delete all entries from lock-less list | ||
| 171 | * @head: the head of lock-less list to delete all entries | ||
| 172 | * | ||
| 173 | * If list is empty, return NULL, otherwise, delete all entries and | ||
| 174 | * return the pointer to the first entry. The order of entries | ||
| 175 | * deleted is from the newest to the oldest added one. | ||
| 176 | */ | ||
| 177 | static inline struct llist_node *llist_del_all(struct llist_head *head) | ||
| 178 | { | ||
| 179 | return xchg(&head->first, NULL); | ||
| 180 | } | ||
| 181 | |||
| 182 | extern bool llist_add_batch(struct llist_node *new_first, | ||
| 183 | struct llist_node *new_last, | ||
| 184 | struct llist_head *head); | ||
| 185 | extern struct llist_node *llist_del_first(struct llist_head *head); | ||
| 186 | |||
| 126 | #endif /* LLIST_H */ | 187 | #endif /* LLIST_H */ |
