void step ( void ) {
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_add_tail ( &process->list, &run_queue );
ref_get ( process->refcnt ); /* Inhibit destruction mid-step */
DBGC2 ( process, "PROCESS %p (%p) finished executing\n",
process, process->step );
ref_put ( process->refcnt ); /* Allow destruction */
- break;
}
}
}
} else {
/* Use first port */
- if ( list_empty ( &fc_ports ) ) {
+ port = list_first_entry ( &fc_ports, struct fc_port, list );
+ if ( ! port ) {
printf ( "No ports\n" );
return 1;
}
- list_for_each_entry ( port, &fc_ports, list )
- break;
}
assert ( port != NULL );
list_check ( (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
*
*signal = rxi->signal;
free ( rxi );
- list_for_each_entry ( iobuf, &dev->mgmt_queue, list ) {
- list_del ( &iobuf->list );
- return iobuf;
- }
- assert ( 0 );
+ assert ( ! list_empty ( &dev->mgmt_queue ) );
+ iobuf = list_first_entry ( &dev->mgmt_queue, struct io_buffer,
+ list );
+ list_del ( &iobuf->list );
+ return iobuf;
}
return NULL;
struct ib_device * last_opened_ibdev ( void ) {
struct ib_device *ibdev;
- list_for_each_entry ( ibdev, &open_ib_devices, open_list ) {
- assert ( ibdev->open_count != 0 );
- return ibdev;
- }
+ ibdev = list_first_entry ( &open_ib_devices, struct ib_device, list );
+ if ( ! ibdev )
+ return NULL;
- return NULL;
+ assert ( ibdev->open_count != 0 );
+ return ibdev;
}
/* Drag in IPoIB */
struct io_buffer * netdev_rx_dequeue ( struct net_device *netdev ) {
struct io_buffer *iobuf;
- list_for_each_entry ( iobuf, &netdev->rx_queue, list ) {
- list_del ( &iobuf->list );
- return iobuf;
- }
- return NULL;
+ iobuf = list_first_entry ( &netdev->rx_queue, struct io_buffer, list );
+ if ( ! iobuf )
+ return NULL;
+
+ list_del ( &iobuf->list );
+ return iobuf;
}
/**
struct net_device * last_opened_netdev ( void ) {
struct net_device *netdev;
- list_for_each_entry ( netdev, &open_net_devices, open_list ) {
- assert ( netdev_is_open ( netdev ) );
- return netdev;
- }
+ netdev = list_first_entry ( &open_net_devices, struct net_device,
+ list );
+ if ( ! netdev )
+ return NULL;
- return NULL;
+ assert ( netdev_is_open ( netdev ) );
+ return netdev;
}
/**
* queue, since tcp_discard() may remove packets from the RX
* queue while we are processing.
*/
- while ( ! list_empty ( &tcp->rx_queue ) ) {
- list_for_each_entry ( iobuf, &tcp->rx_queue, list )
- break;
+ while ( ( iobuf = list_first_entry ( &tcp->rx_queue, struct io_buffer,
+ list ) ) ) {
/* Stop processing when we hit the first gap */
tcpqhdr = iobuf->data;