--- EV-Glib/Glib.xs 2007/12/08 03:17:46 1.4 +++ EV-Glib/Glib.xs 2007/12/08 03:40:32 1.5 @@ -24,6 +24,7 @@ gint maxpri; ev_prepare pw; + ev_check cw; ev_timer tw; GMainContext *gc; @@ -46,14 +47,14 @@ } static void -prepare_cb (EV_P_ ev_prepare *w, int revents) +check_cb (EV_P_ ev_check *w, int revents) { - struct econtext *ctx = (struct econtext *)(((char *)w) - offsetof (struct econtext, pw)); - gint timeout; - int i; + struct econtext *ctx = (struct econtext *)(((char *)w) - offsetof (struct econtext, cw)); if (ctx->nfd >= 0) { + int i; + for (i = 0; i < ctx->nfd; ++i) ev_io_stop (EV_A_ ctx->iow + i); @@ -61,10 +62,21 @@ ev_timer_stop (EV_A_ &ctx->tw); g_main_context_check (ctx->gc, ctx->maxpri, ctx->pfd, ctx->nfd); - g_main_context_dispatch (ctx->gc); ctx->nfd = -1; } +} + +static void +prepare_cb (EV_P_ ev_prepare *w, int revents) +{ + struct econtext *ctx = (struct econtext *)(((char *)w) - offsetof (struct econtext, pw)); + gint timeout; + int i; + + check_cb (EV_A_ &ctx->cw, 0); + + g_main_context_dispatch (ctx->gc); g_main_context_prepare (ctx->gc, &ctx->maxpri); @@ -102,6 +114,7 @@ | (pfd->events & G_IO_OUT ? EV_WRITE : 0) ); iow->data = (void *)pfd; + ev_set_priority (&ctx->cw, ev_priority (w) + 1); ev_io_start (EV_A_ iow); } @@ -138,6 +151,11 @@ ev_prepare_init (&ctx->pw, prepare_cb); ev_prepare_start (EV_DEFAULT_ &ctx->pw); + + ev_check_init (&ctx->cw, check_cb); + ev_set_priority (&ctx->cw, EV_MAXPRI - 1); + ev_check_start (EV_DEFAULT_ &ctx->cw); + ev_init (&ctx->tw, timer_cb); ev_set_priority (&ctx->tw, EV_MINPRI); }