static void time_deregister(libxl__gc *gc, libxl__ev_time *ev)
{
+ libxl__ao_abortable_deregister(&ev->abrt);
+
if (!ev->infinite) {
struct timeval right_away = { 0, 0 };
if (ev->nexus) /* only set if app provided hooks */
#endif
}
+static void time_aborted(libxl__egc *egc, libxl__ao_abortable *abrt, int rc)
+{
+ libxl__ev_time *ev = CONTAINER_OF(abrt, *ev, abrt);
+ EGC_GC;
+
+ time_deregister(gc, ev);
+ DBG("ev_time=%p aborted", ev);
+ ev->func(egc, ev, &ev->abs, rc);
+}
+
+static int time_register_abortable(libxl__ao *ao, libxl__ev_time *ev)
+{
+ ev->abrt.ao = ao;
+ ev->abrt.callback = time_aborted;
+ return libxl__ao_abortable_register(&ev->abrt);
+}
+
int libxl__ev_time_register_abs(libxl__ao *ao, libxl__ev_time *ev,
libxl__ev_time_callback *func,
struct timeval absolute)
DBG("ev_time=%p register abs=%lu.%06lu",
ev, (unsigned long)absolute.tv_sec, (unsigned long)absolute.tv_usec);
+ rc = time_register_abortable(ao, ev);
+ if (rc) goto out;
+
rc = time_register_finite(gc, ev, absolute);
if (rc) goto out;
rc = 0;
out:
+ libxl__ao_abortable_deregister(&ev->abrt);
time_done_debug(gc,__func__,ev,rc);
CTX_UNLOCK;
return rc;
DBG("ev_time=%p register ms=%d", ev, milliseconds);
+ rc = time_register_abortable(ao, ev);
+ if (rc) goto out;
+
if (milliseconds < 0) {
ev->infinite = 1;
} else {
rc = 0;
out:
+ if (!libxl__ev_time_isregistered(ev))
+ libxl__ao_abortable_deregister(&ev->abrt);
time_done_debug(gc,__func__,ev,rc);
CTX_UNLOCK;
return rc;
LIBXL_TAILQ_ENTRY(libxl__ev_time) entry;
struct timeval abs;
libxl__osevent_hook_nexus *nexus;
+ libxl__ao_abortable abrt;
};
typedef struct libxl__ev_xswatch libxl__ev_xswatch;
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_abortable_init(&ev->abrt); }
static inline int libxl__ev_time_isregistered(const libxl__ev_time *ev)
{ return !!ev->func; }