mirror of https://github.com/ipxe/ipxe.git
[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>pull/1/head
parent
295ba15bd6
commit
ea631f6fb8
|
@ -83,7 +83,8 @@ void process_del ( struct process *process ) {
|
||||||
void step ( void ) {
|
void step ( void ) {
|
||||||
struct process *process;
|
struct process *process;
|
||||||
|
|
||||||
list_for_each_entry ( process, &run_queue, list ) {
|
if ( ( process = list_first_entry ( &run_queue, struct process,
|
||||||
|
list ) ) ) {
|
||||||
list_del ( &process->list );
|
list_del ( &process->list );
|
||||||
list_add_tail ( &process->list, &run_queue );
|
list_add_tail ( &process->list, &run_queue );
|
||||||
ref_get ( process->refcnt ); /* Inhibit destruction mid-step */
|
ref_get ( process->refcnt ); /* Inhibit destruction mid-step */
|
||||||
|
@ -93,7 +94,6 @@ void step ( void ) {
|
||||||
DBGC2 ( process, "PROCESS %p (%p) finished executing\n",
|
DBGC2 ( process, "PROCESS %p (%p) finished executing\n",
|
||||||
process, process->step );
|
process, process->step );
|
||||||
ref_put ( process->refcnt ); /* Allow destruction */
|
ref_put ( process->refcnt ); /* Allow destruction */
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -144,12 +144,11 @@ static int fcels_exec ( int argc, char **argv ) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Use first port */
|
/* Use first port */
|
||||||
if ( list_empty ( &fc_ports ) ) {
|
port = list_first_entry ( &fc_ports, struct fc_port, list );
|
||||||
|
if ( ! port ) {
|
||||||
printf ( "No ports\n" );
|
printf ( "No ports\n" );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
list_for_each_entry ( port, &fc_ports, list )
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
assert ( port != NULL );
|
assert ( port != NULL );
|
||||||
|
|
||||||
|
|
|
@ -157,6 +157,19 @@ static inline int list_empty ( const struct list_head *list ) {
|
||||||
list_check ( (list) ); \
|
list_check ( (list) ); \
|
||||||
container_of ( list, type, member ); } )
|
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
|
* Iterate over entries in a list
|
||||||
*
|
*
|
||||||
|
|
|
@ -668,11 +668,11 @@ struct io_buffer * net80211_mgmt_dequeue ( struct net80211_device *dev,
|
||||||
*signal = rxi->signal;
|
*signal = rxi->signal;
|
||||||
free ( rxi );
|
free ( rxi );
|
||||||
|
|
||||||
list_for_each_entry ( iobuf, &dev->mgmt_queue, list ) {
|
assert ( ! list_empty ( &dev->mgmt_queue ) );
|
||||||
list_del ( &iobuf->list );
|
iobuf = list_first_entry ( &dev->mgmt_queue, struct io_buffer,
|
||||||
return iobuf;
|
list );
|
||||||
}
|
list_del ( &iobuf->list );
|
||||||
assert ( 0 );
|
return iobuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -982,12 +982,12 @@ struct ib_device * find_ibdev ( union ib_gid *gid ) {
|
||||||
struct ib_device * last_opened_ibdev ( void ) {
|
struct ib_device * last_opened_ibdev ( void ) {
|
||||||
struct ib_device *ibdev;
|
struct ib_device *ibdev;
|
||||||
|
|
||||||
list_for_each_entry ( ibdev, &open_ib_devices, open_list ) {
|
ibdev = list_first_entry ( &open_ib_devices, struct ib_device, list );
|
||||||
assert ( ibdev->open_count != 0 );
|
if ( ! ibdev )
|
||||||
return ibdev;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
assert ( ibdev->open_count != 0 );
|
||||||
|
return ibdev;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Drag in IPoIB */
|
/* Drag in IPoIB */
|
||||||
|
|
|
@ -328,11 +328,12 @@ void netdev_poll ( struct net_device *netdev ) {
|
||||||
struct io_buffer * netdev_rx_dequeue ( struct net_device *netdev ) {
|
struct io_buffer * netdev_rx_dequeue ( struct net_device *netdev ) {
|
||||||
struct io_buffer *iobuf;
|
struct io_buffer *iobuf;
|
||||||
|
|
||||||
list_for_each_entry ( iobuf, &netdev->rx_queue, list ) {
|
iobuf = list_first_entry ( &netdev->rx_queue, struct io_buffer, list );
|
||||||
list_del ( &iobuf->list );
|
if ( ! iobuf )
|
||||||
return iobuf;
|
return NULL;
|
||||||
}
|
|
||||||
return NULL;
|
list_del ( &iobuf->list );
|
||||||
|
return iobuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -592,12 +593,13 @@ struct net_device * find_netdev_by_location ( unsigned int bus_type,
|
||||||
struct net_device * last_opened_netdev ( void ) {
|
struct net_device * last_opened_netdev ( void ) {
|
||||||
struct net_device *netdev;
|
struct net_device *netdev;
|
||||||
|
|
||||||
list_for_each_entry ( netdev, &open_net_devices, open_list ) {
|
netdev = list_first_entry ( &open_net_devices, struct net_device,
|
||||||
assert ( netdev_is_open ( netdev ) );
|
list );
|
||||||
return netdev;
|
if ( ! netdev )
|
||||||
}
|
return NULL;
|
||||||
|
|
||||||
return NULL;
|
assert ( netdev_is_open ( netdev ) );
|
||||||
|
return netdev;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1014,9 +1014,8 @@ static void tcp_process_rx_queue ( struct tcp_connection *tcp ) {
|
||||||
* queue, since tcp_discard() may remove packets from the RX
|
* queue, since tcp_discard() may remove packets from the RX
|
||||||
* queue while we are processing.
|
* queue while we are processing.
|
||||||
*/
|
*/
|
||||||
while ( ! list_empty ( &tcp->rx_queue ) ) {
|
while ( ( iobuf = list_first_entry ( &tcp->rx_queue, struct io_buffer,
|
||||||
list_for_each_entry ( iobuf, &tcp->rx_queue, list )
|
list ) ) ) {
|
||||||
break;
|
|
||||||
|
|
||||||
/* Stop processing when we hit the first gap */
|
/* Stop processing when we hit the first gap */
|
||||||
tcpqhdr = iobuf->data;
|
tcpqhdr = iobuf->data;
|
||||||
|
|
Loading…
Reference in New Issue