[PATCH -mm -v2 4/5] llist, Return whether list is empty before adding in llist_add

From: Huang Ying
Date: Thu Sep 08 2011 - 02:01:11 EST


This is needed by irq_work. And because list_add_xxx functions are
inline, this can be optimized out if not needed by callers.

Signed-off-by: Huang Ying <ying.huang@xxxxxxxxx>
Cc: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
---
include/linux/llist.h | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

--- a/include/linux/llist.h
+++ b/include/linux/llist.h
@@ -148,8 +148,10 @@ static inline bool llist_empty(const str
* llist_add - add a new entry
* @new: new entry to be added
* @head: the head for your lock-less list
+ *
+ * Return whether list is empty before adding.
*/
-static inline void llist_add(struct llist_node *new, struct llist_head *head)
+static inline bool llist_add(struct llist_node *new, struct llist_head *head)
{
struct llist_node *entry, *old_entry;

@@ -164,6 +166,8 @@ static inline void llist_add(struct llis
break;
cpu_relax();
}
+
+ return old_entry == NULL;
}

/**
@@ -171,8 +175,10 @@ static inline void llist_add(struct llis
* @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.
*/
-static inline void llist_add_batch(struct llist_node *new_first,
+static inline bool llist_add_batch(struct llist_node *new_first,
struct llist_node *new_last,
struct llist_head *head)
{
@@ -189,6 +195,8 @@ static inline void llist_add_batch(struc
break;
cpu_relax();
}
+
+ return old_entry == NULL;
}

/**
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/