qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-block] [RFC PATCH v2] coroutines: generate wrapper code


From: Stefan Hajnoczi
Subject: Re: [Qemu-block] [RFC PATCH v2] coroutines: generate wrapper code
Date: Thu, 21 Feb 2019 10:53:02 +0000
User-agent: Mutt/1.10.1 (2018-07-13)

On Wed, Feb 20, 2019 at 01:03:58PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> Hi all!
> 
> We have a very frequent pattern of creating coroutine from function
> with several arguments:
> 
>   - create structure to pack parameters
>   - create _entry function to call original function taking parameters
>     from struct
>   - do different magic to handle completion: set ret to NOT_DONE or
>     EINPROGRESS, use separate bool for void functions
>   - fill the struct and create coroutine from _entry function and this
>     struct as a parameter
> 
> Here is a template code + example how it can be used to drop a lot of
> similar code.
> 
> TODO: make coroutine-wrapper template file to be header itself, or
>       generate header from it

Yes, please.  For example, block/coroutines.h:

  #include "block/block.h"

  int coroutine_fn bdrv_co_check(BlockDriverState *bs,
                                 BdrvCheckResult *res, BdrvCheckMode fix);
  void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error 
**errp);

Now include/block/block.h doesn't need to be modified and these
coroutine function prototypes stay private to the block layer (they are
not in include/).

The code generator script can parse coroutines.h to generate
__create_co() functions.  This also makes the tool independent of the
block layer - the output C file just needs to include the input header
file:

 /*
  * File is generated by scripts/coroutine-wrapper.py
  */

 #include "qemu/osdep.h"
 #include "block/coroutines.h" <--- from coroutine-wrapper command-line

 ...

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]