Skip to content

Commit

Permalink
llist: Return whether list is empty before adding in llist_add()
Browse files Browse the repository at this point in the history
Extend the llist_add*() functions to return a success indicator, this
allows us in the scheduler code to send an IPI if the queue was empty.

( There's no effect on existing users, because the list_add_xxx() functions
  are inline, thus this will be optimized out by the compiler if not used
  by callers. )

Signed-off-by: Huang Ying <[email protected]>
Cc: Mathieu Desnoyers <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
yhuang-intel authored and Ingo Molnar committed Oct 4, 2011
1 parent a312733 commit 781f7fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion include/linux/llist.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,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;

Expand All @@ -156,6 +158,8 @@ static inline void llist_add(struct llist_node *new, struct llist_head *head)
break;
cpu_relax();
}

return old_entry == NULL;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion lib/llist.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
* @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;
Expand All @@ -49,6 +51,8 @@ void llist_add_batch(struct llist_node *new_first, struct llist_node *new_last,
break;
cpu_relax();
}

return old_entry == NULL;
}
EXPORT_SYMBOL_GPL(llist_add_batch);

Expand Down

0 comments on commit 781f7fd

Please sign in to comment.