[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH 22/28] libxl: ocaml: event management
> > > +value stub_xl_osevent_register_hooks(value ctx, value user) { > > > + CAMLparam2(ctx, user); > > > + libxl_osevent_hooks *hooks; > > > + hooks = malloc(sizeof(*hooks)); > > > + > > > + hooks->fd_register = fd_register; > > > + hooks->fd_modify = fd_modify; > > > + hooks->fd_deregister = fd_deregister; > > > + hooks->timeout_register = timeout_register; > > > + hooks->timeout_modify = timeout_modify; > > > + hooks->timeout_deregister = timeout_deregister; > > > + > > > + libxl_osevent_register_hooks(CTX, hooks, (void *) user); > > > > This user thing will be retained by libxl -- is that safe from an ocaml gc > > point > > of view? > > Good point. The original value may go out of scope in the OCaml program and > will then be GC'ed. We should copy the value to avoid trouble. To do that, > though, we need to know the type of the thing, which is currently > polymorphic. I'll just go ahead and make it a string instead, because that > seems to be the most useful. > > Are these hooks and associated data every cleaned up by libxl? Or is the > assumption that libxl_osevent_register_hooks is just called once at the > beginning of the program, and everything starts till the end? >From the doc comment (libxl_event.h line 353): * osevent_register_hooks may be called only once for each libxl_ctx. So you are not allowed to call it with NULL to deregister or change the hooks. The "user" should normally be a pointer whatever structure you have that contains the libxl_ctx*. > > > +void event_occurs(void *user, const libxl_event *event) { > > > + CAMLparam0(); > > > + CAMLlocalN(args, 2); > > > + value *func = caml_named_value("xl_event_occurs_callback"); > > > + > > > + args[0] = (value) user; > > > + args[1] = Val_event((libxl_event *) event); > > > + //libxl_event_free(CTX, event); // no ctx here! > > > > Is it leaked or do you free it somewhere else? I suppose "func" must do it? > > (which makes sense actually) > > Hmm... This is awkward. The thing we are giving to "func" is the event > translated into an Ocaml type, and not the C libxl_event*. And even if we > give the libxl_event* to "func" as well, it still needs to know the ctx in > order to free it (which it probably would, but won't make things easier to > use). Is there no way to ask libxl to which ctx the event belongs? No, there isn't such a way. Indeed it's not recorded. I think part of the problem here is that you may be trying to map the C functions to ocaml too directly. Your ocaml system already has an event loop, doesn't it ? You should provide plumbing to glue it to that. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |