X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=list.h;h=66c6d91525031261ff94cd3028e672cb340c06cd;hp=de04ab9eed1184451f5338b06a7a2be9106aac5d;hb=a13a1e0d202a8969374b9a70562556e689597f2d;hpb=c6d61cae8b5f71ae658dc254c6ee38a14f34dae2 diff --git a/list.h b/list.h index de04ab9e..66c6d915 100644 --- a/list.h +++ b/list.h @@ -33,6 +33,10 @@ struct list_head { struct list_head *prev; }; +/** Define an initialized list head. */ +#define INITIALIZED_LIST_HEAD(name) struct list_head name = { &(name), &(name) } + + /** must be called before using any other list functions */ #define INIT_LIST_HEAD(ptr) do { \ (ptr)->next = (ptr); (ptr)->prev = (ptr); \ @@ -152,17 +156,6 @@ static inline int list_empty(const struct list_head *head) #define list_entry(ptr, type, member) \ container_of(ptr, type, member) -/** - * iterate over a list safe against removal of list entry - * - * \param pos the &struct list_head to use as a loop counter. - * \param n another &struct list_head to use as temporary storage - * \param head the head for your list. - */ -#define list_for_each_safe(pos, n, head) \ - for (pos = (head)->next, n = pos->next; pos != (head); \ - pos = n, n = pos->next) - /** * iterate over list of given type * @@ -200,3 +193,25 @@ static inline int list_empty(const struct list_head *head) n = list_entry(pos->member.prev, typeof(*pos), member); \ &pos->member != (head); \ pos = n, n = list_entry(n->member.prev, typeof(*n), member)) + +/** + * Get the first element from a list + * \param ptr the list head to take the element from. + * \param type The type of the struct this is embedded in. + * \param member The name of the list_struct within the struct. + * + * Note that list is expected to be not empty. + */ +#define list_first_entry(ptr, type, member) \ + list_entry((ptr)->next, type, member) + +/** + * Test whether a list has just one entry. + * + * \param head The list to test. + */ +static inline int list_is_singular(const struct list_head *head) +{ + return !list_empty(head) && (head->next == head->prev); +} +