rc = libxl__atfork_init(ctx);
if (rc) goto out;
- rc = libxl__poller_init(ctx, &ctx->poller_app);
+ rc = libxl__poller_init(gc, &ctx->poller_app);
if (rc) goto out;
ctx->xch = xc_interface_open(lg,lg,0);
* Manipulation of pollers
*/
-int libxl__poller_init(libxl_ctx *ctx, libxl__poller *p)
+int libxl__poller_init(libxl__gc *gc, libxl__poller *p)
{
int rc;
p->fd_polls = 0;
p->fd_rindices = 0;
- rc = libxl__pipe_nonblock(ctx, p->wakeup_pipe);
+ rc = libxl__pipe_nonblock(CTX, p->wakeup_pipe);
if (rc) goto out;
return 0;
free(p->fd_rindices);
}
-libxl__poller *libxl__poller_get(libxl_ctx *ctx)
+libxl__poller *libxl__poller_get(libxl__gc *gc)
{
/* must be called with ctx locked */
int rc;
- libxl__poller *p = LIBXL_LIST_FIRST(&ctx->pollers_idle);
+ libxl__poller *p = LIBXL_LIST_FIRST(&CTX->pollers_idle);
if (p) {
LIBXL_LIST_REMOVE(p, entry);
return p;
}
- p = malloc(sizeof(*p));
- if (!p) {
- LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "cannot allocate poller");
- return 0;
- }
- memset(p, 0, sizeof(*p));
+ p = libxl__zalloc(NOGC, sizeof(*p));
- rc = libxl__poller_init(ctx, p);
+ rc = libxl__poller_init(gc, p);
if (rc) {
free(p);
return NULL;
EGC_INIT(ctx);
CTX_LOCK;
- poller = libxl__poller_get(ctx);
+ poller = libxl__poller_get(gc);
if (!poller) { rc = ERROR_FAIL; goto out; }
for (;;) {
if (how) {
ao->how = *how;
} else {
- ao->poller = libxl__poller_get(ctx);
+ ao->poller = libxl__poller_get(&ao->gc);
if (!ao->poller) goto out;
}
libxl__log(ctx,XTL_DEBUG,-1,file,line,func,
/* Fills in, or disposes of, the resources held by, a poller whose
* space the caller has allocated. ctx must be locked. */
-_hidden int libxl__poller_init(libxl_ctx *ctx, libxl__poller *p);
+_hidden int libxl__poller_init(libxl__gc *gc, libxl__poller *p);
_hidden void libxl__poller_dispose(libxl__poller *p);
/* Obtain a fresh poller from malloc or the idle list, and put it
* away again afterwards. _get can fail, returning NULL.
* ctx must be locked. */
-_hidden libxl__poller *libxl__poller_get(libxl_ctx *ctx);
+_hidden libxl__poller *libxl__poller_get(libxl__gc *gc);
_hidden void libxl__poller_put(libxl_ctx*, libxl__poller *p /* may be NULL */);
/* Notifies whoever is polling using p that they should wake up.