|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH 23/28] libxl: ocaml: allow device operations to be called asynchronously
On Mon, 2013-03-25 at 14:45 +0000, Rob Hoes wrote:
> Signed-off-by: Rob Hoes <rob.hoes@xxxxxxxxxx>
> ---
> tools/ocaml/libs/xl/genwrap.py | 6 +++---
> tools/ocaml/libs/xl/xenlight_stubs.c | 19 ++++++++++++++++---
> 2 files changed, 19 insertions(+), 6 deletions(-)
>
> diff --git a/tools/ocaml/libs/xl/genwrap.py b/tools/ocaml/libs/xl/genwrap.py
> index 10e6a74..9f7895a 100644
> --- a/tools/ocaml/libs/xl/genwrap.py
> +++ b/tools/ocaml/libs/xl/genwrap.py
> @@ -22,9 +22,9 @@ builtins = {
> "libxl_cpuid_policy_list": ("unit", "%(c)s = 0",
> "Val_unit"),
> }
>
> -DEVICE_FUNCTIONS = [ ("add", ["ctx", "t", "domid", "unit"]),
> - ("remove", ["ctx", "t", "domid", "unit"]),
> - ("destroy", ["ctx", "t", "domid", "unit"]),
> +DEVICE_FUNCTIONS = [ ("add", ["ctx", "?async:'a", "t", "domid",
> "unit"]),
> + ("remove", ["ctx", "?async:'a", "t", "domid",
> "unit"]),
> + ("destroy", ["ctx", "?async:'a", "t", "domid",
> "unit"]),
> ]
>
> functions = { # ( name , [type1,type2,....] )
> diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c
> b/tools/ocaml/libs/xl/xenlight_stubs.c
> index ae5317f..c136db7 100644
> --- a/tools/ocaml/libs/xl/xenlight_stubs.c
> +++ b/tools/ocaml/libs/xl/xenlight_stubs.c
> @@ -338,17 +338,30 @@ void async_callback(libxl_ctx *ctx, int rc, void
> *for_callback)
> #define STRINGIFY(x) _STRINGIFY(x)
>
> #define _DEVICE_ADDREMOVE(type,op) \
> -value stub_xl_device_##type##_##op(value ctx, value info, value domid)
> \
> +value stub_xl_device_##type##_##op(value ctx, value async, value info,
> \
> + value domid) \
> { \
> - CAMLparam3(ctx, info, domid); \
> + CAMLparam4(ctx, info, domid, async); \
> libxl_device_##type c_info; \
> int ret, marker_var; \
> + libxl_asyncop_how *ao_how; \
> \
> device_##type##_val(CTX, &c_info, info); \
> \
> - ret = libxl_device_##type##_##op(CTX, Int_val(domid), &c_info, 0); \
> + if (async != Val_none) { \
> + ao_how = malloc(sizeof(*ao_how)); \
libxl.h says:
* *ao_how does not need to remain valid after the initiating function
* returns. All other parameters must remain valid for the lifetime of
* the asynchronous operation, unless otherwise specified.
So the ao_how can just be a normal stack variable if you like. If you
want to use NULL/non-NULL-ness to indicate Some/None then:
struct ao_how aoh_struct, *aoh = NULL;
if (async != Val_none)
aoh = &aoh_struct
works I think or just
struct ao_how aoh = { .callback = async_callback, ... };
ret = libxl_device_##type##_##op(CTX, Int_val(domid), &c_info, \
async != Val_none ? &aoh : NULL
would do.
> + ao_how->callback = async_callback; \
> + ao_how->u.for_callback = (void *) Some_val(async); \
> + } \
> + else \
> + ao_how = NULL; \
> + \
> + ret = libxl_device_##type##_##op(CTX, Int_val(domid), &c_info, \
> + ao_how); \
> \
> libxl_device_##type##_dispose(&c_info); \
> + if (ao_how) \
> + free(ao_how); \
> \
> if (ret != 0) \
> failwith_xl(ret, STRINGIFY(type) "_" STRINGIFY(op)); \
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |