diff options
author | Michael Brown <mcb30@etherboot.org> | 2007-01-16 08:10:54 +0000 |
---|---|---|
committer | Michael Brown <mcb30@etherboot.org> | 2007-01-16 08:10:54 +0000 |
commit | ff8528ea9a69ca2ef6cfbed0b7a1283e165aabe6 (patch) | |
tree | bae0e953c128a5d49bedd2f502325b938078635f /src | |
parent | f11da20f25ce4535f2731e403071b03f7118d40f (diff) | |
download | ipxe-ff8528ea9a69ca2ef6cfbed0b7a1283e165aabe6.zip ipxe-ff8528ea9a69ca2ef6cfbed0b7a1283e165aabe6.tar.gz ipxe-ff8528ea9a69ca2ef6cfbed0b7a1283e165aabe6.tar.bz2 |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/drivers/ata/aoedev.c | 9 | ||||
-rw-r--r-- | src/drivers/scsi/iscsidev.c | 20 | ||||
-rw-r--r-- | src/include/gpxe/async.h | 36 | ||||
-rw-r--r-- | src/usr/dhcpmgmt.c | 10 | ||||
-rw-r--r-- | src/usr/fetch.c | 7 |
5 files changed, 54 insertions, 28 deletions
diff --git a/src/drivers/ata/aoedev.c b/src/drivers/ata/aoedev.c index 6658827..ff047f1 100644 --- a/src/drivers/ata/aoedev.c +++ b/src/drivers/ata/aoedev.c @@ -17,6 +17,7 @@ */ #include <stddef.h> +#include <gpxe/async.h> #include <gpxe/aoe.h> /** @file @@ -37,13 +38,9 @@ static int aoe_command ( struct ata_device *ata, struct aoe_device *aoedev = container_of ( ata, struct aoe_device, ata ); struct async async; - int rc; - async_init_orphan ( &async ); - if ( ( rc = aoe_issue ( &aoedev->aoe, command, &async ) ) != 0 ) - return rc; - async_wait ( &async, &rc, 1 ); - return rc; + return async_block ( &async, aoe_issue ( &aoedev->aoe, command, + &async ) ); } /** diff --git a/src/drivers/scsi/iscsidev.c b/src/drivers/scsi/iscsidev.c index 75b857e..aab9903 100644 --- a/src/drivers/scsi/iscsidev.c +++ b/src/drivers/scsi/iscsidev.c @@ -17,6 +17,7 @@ */ #include <stddef.h> +#include <gpxe/async.h> #include <gpxe/iscsi.h> /** @file @@ -37,13 +38,9 @@ static int iscsi_command ( struct scsi_device *scsi, struct iscsi_device *iscsidev = container_of ( scsi, struct iscsi_device, scsi ); struct async async; - int rc; - async_init_orphan ( &async ); - if ( ( rc = iscsi_issue ( &iscsidev->iscsi, command, &async ) ) != 0 ) - return rc; - async_wait ( &async, &rc, 1 ); - return rc; + return async_block ( &async, iscsi_issue ( &iscsidev->iscsi, command, + &async ) ); } /** @@ -56,10 +53,13 @@ int init_iscsidev ( struct iscsi_device *iscsidev ) { iscsidev->scsi.command = iscsi_command; iscsidev->scsi.lun = iscsidev->iscsi.lun; - rc = init_scsidev ( &iscsidev->scsi ); - if ( rc != 0 ) { - fini_iscsidev ( iscsidev ); - } + if ( ( rc = init_scsidev ( &iscsidev->scsi ) ) != 0 ) + goto err; + + return 0; + + err: + fini_iscsidev ( iscsidev ); return rc; } diff --git a/src/include/gpxe/async.h b/src/include/gpxe/async.h index d3b075b..b1ca1a1 100644 --- a/src/include/gpxe/async.h +++ b/src/include/gpxe/async.h @@ -167,4 +167,40 @@ static inline aid_t async_init_orphan ( struct async *async ) { 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 */ diff --git a/src/usr/dhcpmgmt.c b/src/usr/dhcpmgmt.c index 90ed62b..6f03027 100644 --- a/src/usr/dhcpmgmt.c +++ b/src/usr/dhcpmgmt.c @@ -20,6 +20,7 @@ #include <byteswap.h> #include <vsprintf.h> #include <gpxe/in.h> +#include <gpxe/ip.h> #include <gpxe/dhcp.h> #include <gpxe/async.h> #include <gpxe/netdevice.h> @@ -65,13 +66,8 @@ int dhcp ( struct net_device *netdev ) { printf ( "DHCP (%s %s)...", netdev->name, netdev_hwaddr ( netdev ) ); memset ( &dhcp, 0, sizeof ( dhcp ) ); dhcp.netdev = netdev; - async_init_orphan ( &async ); - if ( ( rc = start_dhcp ( &dhcp, &async ) ) != 0 ) { - printf ( "could not start (%s)\n", strerror ( rc ) ); - return rc; - } - async_wait ( &async, &rc, 1 ); - if ( rc != 0 ) { + if ( ( rc = async_block ( &async, + start_dhcp ( &dhcp, &async ) ) ) != 0 ) { printf ( "failed (%s)\n", strerror ( rc ) ); return rc; } diff --git a/src/usr/fetch.c b/src/usr/fetch.c index 4503104..11197e9 100644 --- a/src/usr/fetch.c +++ b/src/usr/fetch.c @@ -86,11 +86,8 @@ int fetch ( const char *uri_string, userptr_t *data, size_t *len ) { } } - async_init_orphan ( &async ); - if ( ( rc = download ( uri, &buffer, &async ) ) != 0 ) - goto err; - async_wait ( &async, &rc, 1 ); - if ( rc != 0 ) + if ( ( rc = async_block ( &async, + download ( uri, &buffer, &async ) ) ) != 0 ) goto err; /* Fill in buffer address and length */ |