|  | @@ -170,6 +170,18 @@ static inline int list_empty ( const struct list_head *list ) {
 | 
		
	
		
			
			| 170 | 170 |  	  ( type * ) NULL :				\
 | 
		
	
		
			
			| 171 | 171 |  	  list_entry ( (list)->next, type, member ) )
 | 
		
	
		
			
			| 172 | 172 |  
 | 
		
	
		
			
			|  | 173 | +/**
 | 
		
	
		
			
			|  | 174 | + * Iterate over a list
 | 
		
	
		
			
			|  | 175 | + *
 | 
		
	
		
			
			|  | 176 | + * @v pos		Iterator
 | 
		
	
		
			
			|  | 177 | + * @v head		List head
 | 
		
	
		
			
			|  | 178 | + */
 | 
		
	
		
			
			|  | 179 | +#define list_for_each( pos, head )					      \
 | 
		
	
		
			
			|  | 180 | +	for ( list_check ( (head) ),					      \
 | 
		
	
		
			
			|  | 181 | +	      pos = (head)->next;					      \
 | 
		
	
		
			
			|  | 182 | +	      pos != (head);						      \
 | 
		
	
		
			
			|  | 183 | +	      pos = (pos)->next )
 | 
		
	
		
			
			|  | 184 | +
 | 
		
	
		
			
			| 173 | 185 |  /**
 | 
		
	
		
			
			| 174 | 186 |   * Iterate over entries in a list
 | 
		
	
		
			
			| 175 | 187 |   *
 | 
		
	
	
		
			
			|  | @@ -212,6 +224,38 @@ static inline int list_empty ( const struct list_head *list ) {
 | 
		
	
		
			
			| 212 | 224 |  	      pos = tmp,						      \
 | 
		
	
		
			
			| 213 | 225 |  	      tmp = list_entry ( tmp->member.next, typeof ( *tmp ), member ) )
 | 
		
	
		
			
			| 214 | 226 |  
 | 
		
	
		
			
			|  | 227 | +/**
 | 
		
	
		
			
			|  | 228 | + * Test if list contains a specified entry
 | 
		
	
		
			
			|  | 229 | + *
 | 
		
	
		
			
			|  | 230 | + * @v entry		Entry
 | 
		
	
		
			
			|  | 231 | + * @v head		List head
 | 
		
	
		
			
			|  | 232 | + * @ret present		List contains specified entry
 | 
		
	
		
			
			|  | 233 | + */
 | 
		
	
		
			
			|  | 234 | +static inline int list_contains ( struct list_head *entry,
 | 
		
	
		
			
			|  | 235 | +				  struct list_head *head ) {
 | 
		
	
		
			
			|  | 236 | +	struct list_head *tmp;
 | 
		
	
		
			
			|  | 237 | +
 | 
		
	
		
			
			|  | 238 | +	list_for_each ( tmp, head ) {
 | 
		
	
		
			
			|  | 239 | +		if ( tmp == entry )
 | 
		
	
		
			
			|  | 240 | +			return 1;
 | 
		
	
		
			
			|  | 241 | +	}
 | 
		
	
		
			
			|  | 242 | +	return 0;
 | 
		
	
		
			
			|  | 243 | +}
 | 
		
	
		
			
			|  | 244 | +#define list_contains( entry, head ) ( {		\
 | 
		
	
		
			
			|  | 245 | +	list_check ( (head) );				\
 | 
		
	
		
			
			|  | 246 | +	list_check ( (entry) );				\
 | 
		
	
		
			
			|  | 247 | +	list_contains ( (entry), (head) ); } )
 | 
		
	
		
			
			|  | 248 | +
 | 
		
	
		
			
			|  | 249 | +/**
 | 
		
	
		
			
			|  | 250 | + * Test if list contains a specified entry
 | 
		
	
		
			
			|  | 251 | + *
 | 
		
	
		
			
			|  | 252 | + * @v entry		Entry
 | 
		
	
		
			
			|  | 253 | + * @v head		List head
 | 
		
	
		
			
			|  | 254 | + * @ret present		List contains specified entry
 | 
		
	
		
			
			|  | 255 | + */
 | 
		
	
		
			
			|  | 256 | +#define list_contains_entry( entry, head, member )	\
 | 
		
	
		
			
			|  | 257 | +	list_contains ( &(entry)->member, (head) )
 | 
		
	
		
			
			|  | 258 | +
 | 
		
	
		
			
			| 215 | 259 |  /**
 | 
		
	
		
			
			| 216 | 260 |   * Check list contains a specified entry
 | 
		
	
		
			
			| 217 | 261 |   *
 | 
		
	
	
		
			
			|  | @@ -219,16 +263,8 @@ static inline int list_empty ( const struct list_head *list ) {
 | 
		
	
		
			
			| 219 | 263 |   * @v head		List head
 | 
		
	
		
			
			| 220 | 264 |   * @v member		Name of list field within iterator's type
 | 
		
	
		
			
			| 221 | 265 |   */
 | 
		
	
		
			
			| 222 |  | -#define list_check_contains( entry, head, member ) do {		\
 | 
		
	
		
			
			| 223 |  | -	if ( ASSERTING ) {					\
 | 
		
	
		
			
			| 224 |  | -		typeof ( entry ) tmp;				\
 | 
		
	
		
			
			| 225 |  | -		int found = 0;					\
 | 
		
	
		
			
			| 226 |  | -		list_for_each_entry ( tmp, head, member ) {	\
 | 
		
	
		
			
			| 227 |  | -			if ( tmp == entry )			\
 | 
		
	
		
			
			| 228 |  | -				found = 1;			\
 | 
		
	
		
			
			| 229 |  | -		}						\
 | 
		
	
		
			
			| 230 |  | -		assert ( found );				\
 | 
		
	
		
			
			| 231 |  | -	}							\
 | 
		
	
		
			
			|  | 266 | +#define list_check_contains_entry( entry, head, member ) do {		      \
 | 
		
	
		
			
			|  | 267 | +	assert ( list_contains_entry ( (entry), (head), member ) );	      \
 | 
		
	
		
			
			| 232 | 268 |  	} while ( 0 )
 | 
		
	
		
			
			| 233 | 269 |  
 | 
		
	
		
			
			| 234 | 270 |  #endif /* _IPXE_LIST_H */
 |