for (i = 0; i < ctx->watch_nslots; i++)
assert(!libxl__watch_slot_contents(gc, i));
- libxl__ev_fd_deregister(gc, &ctx->watch_efd);
+ assert(!libxl__ev_fd_isregistered(&ctx->watch_efd));
libxl__ev_fd_deregister(gc, &ctx->evtchn_efd);
libxl__ev_fd_deregister(gc, &ctx->sigchld_selfpipe_efd);
return libxl__sprintf(gc, "%d/%"PRIx32, slotnum, counterval);
}
+static void watches_check_fd_deregister(libxl__gc *gc)
+{
+ assert(CTX->nwatches>=0);
+ if (!CTX->nwatches)
+ libxl__ev_fd_deregister(gc, &CTX->watch_efd);
+}
+
int libxl__ev_xswatch_register(libxl__gc *gc, libxl__ev_xswatch *w,
libxl__ev_xswatch_callback *func,
const char *path /* copied */)
w->slotnum = slotnum;
w->path = path_copy;
w->callback = func;
+ CTX->nwatches++;
libxl__set_watch_slot_contents(use, w);
CTX_UNLOCK;
if (use)
LIBXL_SLIST_INSERT_HEAD(&CTX->watch_freeslots, use, empty);
free(path_copy);
+ watches_check_fd_deregister(gc);
CTX_UNLOCK;
return rc;
}
libxl__ev_watch_slot *slot = &CTX->watch_slots[w->slotnum];
LIBXL_SLIST_INSERT_HEAD(&CTX->watch_freeslots, slot, empty);
w->slotnum = -1;
+ CTX->nwatches--;
+ watches_check_fd_deregister(gc);
} else {
LOG(DEBUG, "watch w=%p: deregister unregistered", w);
}
LIBXL_TAILQ_HEAD(, libxl__ev_time) etimes;
libxl__ev_watch_slot *watch_slots;
- int watch_nslots;
+ int watch_nslots, nwatches;
LIBXL_SLIST_HEAD(, libxl__ev_watch_slot) watch_freeslots;
uint32_t watch_counter; /* helps disambiguate slot reuse */
libxl__ev_fd watch_efd;