Create and use async_block() macro; it cuts down on the visual overhead
of blocking on asynchronous operations, when that isn't an important aspect of the code.
This commit is contained in:
parent
f11da20f25
commit
ff8528ea9a
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <gpxe/async.h>
|
||||||
#include <gpxe/aoe.h>
|
#include <gpxe/aoe.h>
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
|
@ -37,13 +38,9 @@ static int aoe_command ( struct ata_device *ata,
|
||||||
struct aoe_device *aoedev
|
struct aoe_device *aoedev
|
||||||
= container_of ( ata, struct aoe_device, ata );
|
= container_of ( ata, struct aoe_device, ata );
|
||||||
struct async async;
|
struct async async;
|
||||||
int rc;
|
|
||||||
|
|
||||||
async_init_orphan ( &async );
|
return async_block ( &async, aoe_issue ( &aoedev->aoe, command,
|
||||||
if ( ( rc = aoe_issue ( &aoedev->aoe, command, &async ) ) != 0 )
|
&async ) );
|
||||||
return rc;
|
|
||||||
async_wait ( &async, &rc, 1 );
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <gpxe/async.h>
|
||||||
#include <gpxe/iscsi.h>
|
#include <gpxe/iscsi.h>
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
|
@ -37,13 +38,9 @@ static int iscsi_command ( struct scsi_device *scsi,
|
||||||
struct iscsi_device *iscsidev
|
struct iscsi_device *iscsidev
|
||||||
= container_of ( scsi, struct iscsi_device, scsi );
|
= container_of ( scsi, struct iscsi_device, scsi );
|
||||||
struct async async;
|
struct async async;
|
||||||
int rc;
|
|
||||||
|
|
||||||
async_init_orphan ( &async );
|
return async_block ( &async, iscsi_issue ( &iscsidev->iscsi, command,
|
||||||
if ( ( rc = iscsi_issue ( &iscsidev->iscsi, command, &async ) ) != 0 )
|
&async ) );
|
||||||
return rc;
|
|
||||||
async_wait ( &async, &rc, 1 );
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,10 +53,13 @@ int init_iscsidev ( struct iscsi_device *iscsidev ) {
|
||||||
|
|
||||||
iscsidev->scsi.command = iscsi_command;
|
iscsidev->scsi.command = iscsi_command;
|
||||||
iscsidev->scsi.lun = iscsidev->iscsi.lun;
|
iscsidev->scsi.lun = iscsidev->iscsi.lun;
|
||||||
rc = init_scsidev ( &iscsidev->scsi );
|
if ( ( rc = init_scsidev ( &iscsidev->scsi ) ) != 0 )
|
||||||
if ( rc != 0 ) {
|
goto err;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
err:
|
||||||
fini_iscsidev ( iscsidev );
|
fini_iscsidev ( iscsidev );
|
||||||
}
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,4 +167,40 @@ static inline aid_t async_init_orphan ( struct async *async ) {
|
||||||
return async_init ( async, &orphan_async_operations, NULL );
|
return async_init ( async, &orphan_async_operations, NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute and block on an asynchronous operation
|
||||||
|
*
|
||||||
|
* @v async_temp Temporary asynchronous operation structure to use
|
||||||
|
* @v START Code used to start the asynchronous operation
|
||||||
|
* @ret rc Return status code
|
||||||
|
*
|
||||||
|
* This is a notational shorthand for writing
|
||||||
|
*
|
||||||
|
* async_init_orphan ( &async_temp );
|
||||||
|
* if ( ( rc = START ) == 0 )
|
||||||
|
* async_wait ( &async_temp );
|
||||||
|
* if ( rc != 0 ) {
|
||||||
|
* ...handle failure...
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* and allows you instead to write
|
||||||
|
*
|
||||||
|
* if ( ( rc = async_block ( &async_temp, START ) ) != 0 ) {
|
||||||
|
* ...handle failure...
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* The argument START is a code snippet; it should initiate an
|
||||||
|
* asynchronous operation as a child of @c async_temp and return an
|
||||||
|
* error status code if it failed to do so (e.g. due to malloc()
|
||||||
|
* failure).
|
||||||
|
*/
|
||||||
|
#define async_block( async_temp, START ) ( { \
|
||||||
|
int rc; \
|
||||||
|
\
|
||||||
|
async_init_orphan ( async_temp ); \
|
||||||
|
if ( ( rc = START ) == 0 ) \
|
||||||
|
async_wait ( async_temp, &rc, 1 ); \
|
||||||
|
rc; \
|
||||||
|
} )
|
||||||
|
|
||||||
#endif /* _GPXE_ASYNC_H */
|
#endif /* _GPXE_ASYNC_H */
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <byteswap.h>
|
#include <byteswap.h>
|
||||||
#include <vsprintf.h>
|
#include <vsprintf.h>
|
||||||
#include <gpxe/in.h>
|
#include <gpxe/in.h>
|
||||||
|
#include <gpxe/ip.h>
|
||||||
#include <gpxe/dhcp.h>
|
#include <gpxe/dhcp.h>
|
||||||
#include <gpxe/async.h>
|
#include <gpxe/async.h>
|
||||||
#include <gpxe/netdevice.h>
|
#include <gpxe/netdevice.h>
|
||||||
|
@ -65,13 +66,8 @@ int dhcp ( struct net_device *netdev ) {
|
||||||
printf ( "DHCP (%s %s)...", netdev->name, netdev_hwaddr ( netdev ) );
|
printf ( "DHCP (%s %s)...", netdev->name, netdev_hwaddr ( netdev ) );
|
||||||
memset ( &dhcp, 0, sizeof ( dhcp ) );
|
memset ( &dhcp, 0, sizeof ( dhcp ) );
|
||||||
dhcp.netdev = netdev;
|
dhcp.netdev = netdev;
|
||||||
async_init_orphan ( &async );
|
if ( ( rc = async_block ( &async,
|
||||||
if ( ( rc = start_dhcp ( &dhcp, &async ) ) != 0 ) {
|
start_dhcp ( &dhcp, &async ) ) ) != 0 ) {
|
||||||
printf ( "could not start (%s)\n", strerror ( rc ) );
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
async_wait ( &async, &rc, 1 );
|
|
||||||
if ( rc != 0 ) {
|
|
||||||
printf ( "failed (%s)\n", strerror ( rc ) );
|
printf ( "failed (%s)\n", strerror ( rc ) );
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,11 +86,8 @@ int fetch ( const char *uri_string, userptr_t *data, size_t *len ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async_init_orphan ( &async );
|
if ( ( rc = async_block ( &async,
|
||||||
if ( ( rc = download ( uri, &buffer, &async ) ) != 0 )
|
download ( uri, &buffer, &async ) ) ) != 0 )
|
||||||
goto err;
|
|
||||||
async_wait ( &async, &rc, 1 );
|
|
||||||
if ( rc != 0 )
|
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/* Fill in buffer address and length */
|
/* Fill in buffer address and length */
|
||||||
|
|
Reference in New Issue