[list] Add list_next_entry() and list_prev_entry()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2016-08-31 15:05:22 +01:00
parent ff28b22568
commit 161c80af5b
2 changed files with 51 additions and 0 deletions

View File

@@ -348,6 +348,34 @@ extern void extern_list_splice_tail_init ( struct list_head *list,
( type * ) NULL : \
list_entry ( (list)->prev, type, member ) )
/**
* Get the container of the next entry in a list
*
* @v pos Current list entry
* @v head List head
* @v member Name of list field within iterator's type
* @ret next Next list entry, or NULL at end of list
*/
#define list_next_entry( pos, head, member ) ( { \
typeof (pos) next = list_entry ( (pos)->member.next, \
typeof ( *(pos) ), \
member ); \
( ( &next->member == (head) ) ? NULL : next ); } )
/**
* Get the container of the previous entry in a list
*
* @v pos Current list entry
* @v head List head
* @v member Name of list field within iterator's type
* @ret next Next list entry, or NULL at end of list
*/
#define list_prev_entry( pos, head, member ) ( { \
typeof (pos) prev = list_entry ( (pos)->member.prev, \
typeof ( *(pos) ), \
member ); \
( ( &prev->member == (head) ) ? NULL : prev ); } )
/**
* Iterate over a list
*