From: Ian Campbell Subject: Re: [PATCH 8/9] libxl: Introduce libxl__ev_devstate Date: Thu, 19 Jan 2012 10:54:02 +0000 Message-ID: <1326970442.17599.53.camel@zakaz.uk.xensource.com> References: <1326482728-10733-1-git-send-email-ian.jackson@eu.citrix.com> <1326482728-10733-9-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1326482728-10733-9-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Ian Jackson Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org On Fri, 2012-01-13 at 19:25 +0000, Ian Jackson wrote: > Provide a new-style asynchronous facility for waiting for device > states on xenbus. This will replace libxl__wait_for_device_state, > after the callers have been updated in later patches. Is event-with-timeout likely to be a useful/common enough pattern to be worth baking into the infrastructure/helpers rather than implementing just for this one event type? (if yes then, "I will refactor for the second user is a valid response"). > Signed-off-by: Ian Jackson > --- > tools/libxl/libxl_event.c | 75 ++++++++++++++++++++++++++++++++++++++++++ > tools/libxl/libxl_internal.h | 41 +++++++++++++++++++++++ > 2 files changed, 116 insertions(+), 0 deletions(-) > > diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c > index b99049a..1d271b8 100644 > --- a/tools/libxl/libxl_event.c > +++ b/tools/libxl/libxl_event.c > @@ -507,6 +507,81 @@ void libxl__ev_xswatch_deregister(libxl__gc *gc, libxl__ev_xswatch *w) [...] > + libxl__ev_devstate_cancel(gc, ds); > + ds->callback(egc, ds, rc); > +} > + > +static void devstate_timeout(libxl__egc *egc, libxl__ev_time *ev, > + const struct timeval *requested_abs) > +{ > + EGC_GC; > + libxl__ev_devstate *ds = CONTAINER_OF(ev, *ds, timeout); > + LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, "backend %s wanted state %d " > + " timed out", ds->watch.path, ds->wanted); > + libxl__ev_devstate_cancel(gc, ds); What prevents racing here with the watch happening? Might the caller see two callbacks? > + ds->callback(egc, ds, ERROR_TIMEDOUT); > +} > +