import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / llist.h
index a5199f6d0e82592dde0e4ba7908b1d1b70323483..97cf31da6be240e3ffc331f42dc087a0b8d78eb3 100644 (file)
@@ -124,6 +124,29 @@ static inline void init_llist_head(struct llist_head *list)
             &(pos)->member != NULL;                                    \
             (pos) = llist_entry((pos)->member.next, typeof(*(pos)), member))
 
+/**
+ * llist_for_each_entry_safe - iterate over some deleted entries of lock-less list of given type
+ *                            safe against removal of list entry
+ * @pos:       the type * to use as a loop cursor.
+ * @n:         another type * to use as temporary storage
+ * @node:      the first entry of deleted list entries.
+ * @member:    the name of the llist_node with the struct.
+ *
+ * In general, some entries of the lock-less list can be traversed
+ * safely only after being removed from list, so start with an entry
+ * instead of list head.
+ *
+ * If being used on entries deleted from lock-less list directly, the
+ * traverse order is from the newest to the oldest added entry.  If
+ * you want to traverse from the oldest to the newest, you must
+ * reverse the order by yourself before traversing.
+ */
+#define llist_for_each_entry_safe(pos, n, node, member)                               \
+       for (pos = llist_entry((node), typeof(*pos), member);                  \
+            &pos->member != NULL &&                                           \
+               (n = llist_entry(pos->member.next, typeof(*n), member), true); \
+            pos = n)
+
 /**
  * llist_empty - tests whether a lock-less list is empty
  * @head:      the list to test