mirror of
https://github.com/xcat2/xNBA.git
synced 2024-11-29 21:00:24 +00:00
[list] Add list_last_entry()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
parent
8a0331c29b
commit
6ba7fb7c5c
@ -324,6 +324,19 @@ static inline void list_splice_tail_init ( struct list_head *list,
|
||||
( type * ) NULL : \
|
||||
list_entry ( (list)->next, type, member ) )
|
||||
|
||||
/**
|
||||
* Get the container of the last entry in a list
|
||||
*
|
||||
* @v list List head
|
||||
* @v type Containing type
|
||||
* @v member Name of list field within containing type
|
||||
* @ret first First list entry, or NULL
|
||||
*/
|
||||
#define list_last_entry( list, type, member ) \
|
||||
( list_empty ( (list) ) ? \
|
||||
( type * ) NULL : \
|
||||
list_entry ( (list)->prev, type, member ) )
|
||||
|
||||
/**
|
||||
* Iterate over a list
|
||||
*
|
||||
|
@ -368,16 +368,28 @@ static void list_test_exec ( void ) {
|
||||
ok ( list_entry ( &list_tests[3].list, struct list_test, list )
|
||||
== &list_tests[3] );
|
||||
|
||||
/* Test list_first_entry() */
|
||||
/* Test list_first_entry() and list_last_entry() */
|
||||
INIT_LIST_HEAD ( list );
|
||||
list_add_tail ( &list_tests[9].list, list );
|
||||
list_add_tail ( &list_tests[5].list, list );
|
||||
list_add_tail ( &list_tests[6].list, list );
|
||||
ok ( list_first_entry ( list, struct list_test, list )
|
||||
== &list_tests[9] );
|
||||
ok ( list_last_entry ( list, struct list_test, list )
|
||||
== &list_tests[6] );
|
||||
list_del ( &list_tests[9].list );
|
||||
ok ( list_first_entry ( list, struct list_test, list )
|
||||
== &list_tests[5] );
|
||||
ok ( list_last_entry ( list, struct list_test, list )
|
||||
== &list_tests[6] );
|
||||
list_del ( &list_tests[6].list );
|
||||
ok ( list_first_entry ( list, struct list_test, list )
|
||||
== &list_tests[5] );
|
||||
ok ( list_last_entry ( list, struct list_test, list )
|
||||
== &list_tests[5] );
|
||||
list_del ( &list_tests[5].list );
|
||||
ok ( list_first_entry ( list, struct list_test, list ) == NULL );
|
||||
ok ( list_last_entry ( list, struct list_test, list ) == NULL );
|
||||
|
||||
/* Test list_for_each() */
|
||||
INIT_LIST_HEAD ( list );
|
||||
|
Loading…
Reference in New Issue
Block a user