diff options
author | Michael Brown | 2010-11-08 03:51:18 +0100 |
---|---|---|
committer | Michael Brown | 2010-11-08 04:15:28 +0100 |
commit | ea631f6fb8dbffe3081ecf29eafa62ecd38ec64f (patch) | |
tree | f27d347fc48c524e172a4bdeea80976a26b9904a /src/include/ipxe/list.h | |
parent | [list] Extend list-manipulation assertions to all list-handling functions (diff) | |
download | ipxe-ea631f6fb8dbffe3081ecf29eafa62ecd38ec64f.tar.gz ipxe-ea631f6fb8dbffe3081ecf29eafa62ecd38ec64f.tar.xz ipxe-ea631f6fb8dbffe3081ecf29eafa62ecd38ec64f.zip |
[list] Add list_first_entry()
There are several points in the iPXE codebase where
list_for_each_entry() is (ab)used to extract only the first entry from
a list. Add a macro list_first_entry() to make this code easier to
read.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe/list.h')
-rw-r--r-- | src/include/ipxe/list.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/include/ipxe/list.h b/src/include/ipxe/list.h index fb00bc53..ab4c119d 100644 --- a/src/include/ipxe/list.h +++ b/src/include/ipxe/list.h @@ -158,6 +158,19 @@ static inline int list_empty ( const struct list_head *list ) { container_of ( list, type, member ); } ) /** + * Get the container of the first 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_first_entry( list, type, member ) \ + ( list_empty ( (list) ) ? \ + ( type * ) NULL : \ + list_entry ( (list)->next, type, member ) ) + +/** * Iterate over entries in a list * * @v pos Iterator |