From 34670f4c5b7ed31fda201a0aca35c5cbcea67ffd Mon Sep 17 00:00:00 2001 From: Huang Ying Date: Wed, 28 Sep 2011 10:50:48 +1000 Subject: [PATCH] llist: return whether list is empty before adding in llist_add 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 Cc: Mathieu Desnoyers Cc: Peter Zijlstra Signed-off-by: Andrew Morton <> --- include/linux/llist.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/include/linux/llist.h b/include/linux/llist.h index 32510931b23b..48f49e91bf2e 100644 --- a/include/linux/llist.h +++ b/include/linux/llist.h @@ -148,8 +148,10 @@ static inline bool llist_empty(const struct llist_head *head) * 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 llist_node *new, struct llist_head *head) break; cpu_relax(); } + + return old_entry == NULL; } /** @@ -171,8 +175,10 @@ static inline void llist_add(struct llist_node *new, struct llist_head *head) * @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(struct llist_node *new_first, break; cpu_relax(); } + + return old_entry == NULL; } /** -- 2.39.2