diff options
author | Michael Brown <mcb30@ipxe.org> | 2011-10-14 13:35:05 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2011-10-14 14:33:31 +0100 |
commit | 38b205d0a4d7c29f7ba32f3f96e4ded9790d0af2 (patch) | |
tree | 07b6755344d0ebd251d299f81e65f8ef0f5f2e6d /src/include/ipxe/list.h | |
parent | 12767d2202e620e32aef3fbdd2c4ad30c4e5ac22 (diff) | |
download | ipxe-38b205d0a4d7c29f7ba32f3f96e4ded9790d0af2.zip ipxe-38b205d0a4d7c29f7ba32f3f96e4ded9790d0af2.tar.gz ipxe-38b205d0a4d7c29f7ba32f3f96e4ded9790d0af2.tar.bz2 |
[list] Tidy up naming convention for list_contains() and friends
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe/list.h')
-rw-r--r-- | src/include/ipxe/list.h | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/src/include/ipxe/list.h b/src/include/ipxe/list.h index 4905aaa..8dc7413 100644 --- a/src/include/ipxe/list.h +++ b/src/include/ipxe/list.h @@ -171,6 +171,18 @@ static inline int list_empty ( const struct list_head *list ) { list_entry ( (list)->next, type, member ) ) /** + * Iterate over a list + * + * @v pos Iterator + * @v head List head + */ +#define list_for_each( pos, head ) \ + for ( list_check ( (head) ), \ + pos = (head)->next; \ + pos != (head); \ + pos = (pos)->next ) + +/** * Iterate over entries in a list * * @v pos Iterator @@ -213,22 +225,46 @@ static inline int list_empty ( const struct list_head *list ) { tmp = list_entry ( tmp->member.next, typeof ( *tmp ), member ) ) /** + * Test if list contains a specified entry + * + * @v entry Entry + * @v head List head + * @ret present List contains specified entry + */ +static inline int list_contains ( struct list_head *entry, + struct list_head *head ) { + struct list_head *tmp; + + list_for_each ( tmp, head ) { + if ( tmp == entry ) + return 1; + } + return 0; +} +#define list_contains( entry, head ) ( { \ + list_check ( (head) ); \ + list_check ( (entry) ); \ + list_contains ( (entry), (head) ); } ) + +/** + * Test if list contains a specified entry + * + * @v entry Entry + * @v head List head + * @ret present List contains specified entry + */ +#define list_contains_entry( entry, head, member ) \ + list_contains ( &(entry)->member, (head) ) + +/** * Check list contains a specified entry * * @v entry Entry * @v head List head * @v member Name of list field within iterator's type */ -#define list_check_contains( entry, head, member ) do { \ - if ( ASSERTING ) { \ - typeof ( entry ) tmp; \ - int found = 0; \ - list_for_each_entry ( tmp, head, member ) { \ - if ( tmp == entry ) \ - found = 1; \ - } \ - assert ( found ); \ - } \ +#define list_check_contains_entry( entry, head, member ) do { \ + assert ( list_contains_entry ( (entry), (head), member ) ); \ } while ( 0 ) #endif /* _IPXE_LIST_H */ |