Skip to content

Commit

Permalink
list.h: add list_is_singular()
Browse files Browse the repository at this point in the history
Add list_is_singular() to check a list has just one entry.

list_is_singular() is useful to check whether a list_head which have been
temporarily allocated for listing objects can be released or not.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Masami Hiramatsu authored and Linus Torvalds committed Apr 28, 2008
1 parent 3d8d996 commit 9960257
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/linux/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@ static inline int list_empty_careful(const struct list_head *head)
return (next == head) && (next == head->prev);
}

/**
* list_is_singular - tests whether a list has just one entry.
* @head: the list to test.
*/
static inline int list_is_singular(const struct list_head *head)
{
return !list_empty(head) && (head->next == head->prev);
}

static inline void __list_splice(struct list_head *list,
struct list_head *head)
{
Expand Down

0 comments on commit 9960257

Please sign in to comment.