From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: [PATCH 19/29] libxl: cancellation: Make timeouts cancellable Date: Tue, 10 Feb 2015 20:10:06 +0000 Message-ID: <1423599016-32639-20-git-send-email-ian.jackson@eu.citrix.com> References: <1423599016-32639-1-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: <1423599016-32639-1-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xensource.com Cc: Ian Jackson , Euan Harris List-Id: xen-devel@lists.xenproject.org Make libxl__ev_time* register with the cancellation machinery, so that libxl_ao_cancel can cancel any operation which has a timeout. Signed-off-by: Ian Jackson --- tools/libxl/libxl_event.c | 27 +++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 3 ++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c index d3658f1..ba549f2 100644 --- a/tools/libxl/libxl_event.c +++ b/tools/libxl/libxl_event.c @@ -292,6 +292,8 @@ static int time_register_finite(libxl__gc *gc, libxl__ev_time *ev, static void time_deregister(libxl__gc *gc, libxl__ev_time *ev) { + libxl__ao_cancellable_deregister(&ev->cancel); + if (!ev->infinite) { struct timeval right_away = { 0, 0 }; if (ev->nexus) /* only set if app provided hooks */ @@ -314,6 +316,23 @@ static void time_done_debug(libxl__gc *gc, const char *func, #endif } +static void time_cancelled(libxl__egc *egc, libxl__ao_cancellable *canc, int rc) +{ + libxl__ev_time *ev = CONTAINER_OF(canc, *ev, cancel); + EGC_GC; + + time_deregister(gc, ev); + DBG("ev_time=%p cancelled", ev); + ev->func(egc, ev, &ev->abs, rc); +} + +static int time_register_cancel(libxl__ao *ao, libxl__ev_time *ev) +{ + ev->cancel.ao = ao; + ev->cancel.callback = time_cancelled; + return libxl__ao_cancellable_register(&ev->cancel); +} + int libxl__ev_time_register_abs(libxl__ao *ao, libxl__ev_time *ev, libxl__ev_time_callback *func, struct timeval absolute) @@ -326,6 +345,9 @@ int libxl__ev_time_register_abs(libxl__ao *ao, libxl__ev_time *ev, DBG("ev_time=%p register abs=%lu.%06lu", ev, (unsigned long)absolute.tv_sec, (unsigned long)absolute.tv_usec); + rc = time_register_cancel(ao, ev); + if (rc) goto out; + rc = time_register_finite(gc, ev, absolute); if (rc) goto out; @@ -333,6 +355,7 @@ int libxl__ev_time_register_abs(libxl__ao *ao, libxl__ev_time *ev, rc = 0; out: + libxl__ao_cancellable_deregister(&ev->cancel); time_done_debug(gc,__func__,ev,rc); CTX_UNLOCK; return rc; @@ -351,6 +374,9 @@ int libxl__ev_time_register_rel(libxl__ao *ao, libxl__ev_time *ev, DBG("ev_time=%p register ms=%d", ev, milliseconds); + rc = time_register_cancel(ao, ev); + if (rc) goto out; + if (milliseconds < 0) { ev->infinite = 1; } else { @@ -365,6 +391,7 @@ int libxl__ev_time_register_rel(libxl__ao *ao, libxl__ev_time *ev, rc = 0; out: + libxl__ao_cancellable_deregister(&ev->cancel); time_done_debug(gc,__func__,ev,rc); CTX_UNLOCK; return rc; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 6caf042..790a489 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -223,6 +223,7 @@ struct libxl__ev_time { LIBXL_TAILQ_ENTRY(libxl__ev_time) entry; struct timeval abs; libxl__osevent_hook_nexus *nexus; + libxl__ao_cancellable cancel; }; typedef struct libxl__ev_xswatch libxl__ev_xswatch; @@ -828,7 +829,7 @@ _hidden int libxl__ev_time_modify_abs(libxl__gc*, libxl__ev_time *ev, struct timeval); _hidden void libxl__ev_time_deregister(libxl__gc*, libxl__ev_time *ev); static inline void libxl__ev_time_init(libxl__ev_time *ev) - { ev->func = 0; } + { ev->func = 0; libxl__ao_cancellable_init(&ev->cancel); } static inline int libxl__ev_time_isregistered(const libxl__ev_time *ev) { return !!ev->func; } -- 1.7.10.4