]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - lib/llist.c
[media] staging: as102: Remove conditional compilation based on kernel version
[karo-tx-linux.git] / lib / llist.c
index b445f2c8596ac20aba66e3bc58b2816f0c095cb1..700cff77a3870a04ca050b92b47f1a93c04368e3 100644 (file)
  * @new_first: first entry in batch to be added
  * @new_last:  last entry in batch to be added
  * @head:      the head for your lock-less list
+ *
+ * Return whether list is empty before adding.
  */
-void llist_add_batch(struct llist_node *new_first, struct llist_node *new_last,
+bool llist_add_batch(struct llist_node *new_first, struct llist_node *new_last,
                     struct llist_head *head)
 {
        struct llist_node *entry, *old_entry;
 
        entry = head->first;
-       do {
+       for (;;) {
                old_entry = entry;
                new_last->next = entry;
-               cpu_relax();
-       } while ((entry = cmpxchg(&head->first, old_entry, new_first)) != old_entry);
+               entry = cmpxchg(&head->first, old_entry, new_first);
+               if (entry == old_entry)
+                       break;
+       }
+
+       return old_entry == NULL;
 }
 EXPORT_SYMBOL_GPL(llist_add_batch);
 
@@ -68,13 +74,15 @@ struct llist_node *llist_del_first(struct llist_head *head)
        struct llist_node *entry, *old_entry, *next;
 
        entry = head->first;
-       do {
+       for (;;) {
                if (entry == NULL)
                        return NULL;
                old_entry = entry;
                next = entry->next;
-               cpu_relax();
-       } while ((entry = cmpxchg(&head->first, old_entry, next)) != old_entry);
+               entry = cmpxchg(&head->first, old_entry, next);
+               if (entry == old_entry)
+                       break;
+       }
 
        return entry;
 }