static int call_spoll(void) { int timeout = 24*3600*1000; block_async_poll(); for (poll_functions_t *src=sources; src; src=src->next) if (src->spoll) { int ms = (*src->spoll)(); if (ms>0 && ms<timeout) timeout = ms; } unblock_async_poll(); return timeout; }
/* event_wait -- Waits until events become available. Returns handler of first available event. Also wait for console input if <console> is true. */ at * event_wait(int console) { at *hndl = 0; int cinput = 0; int toggle = 1; block_async_poll(); for (;;) { int n, ms1, ms2; struct poll_functions *src; if ((hndl = ev_peek())) break; ms1 = call_spoll(); if ((hndl = ev_peek())) break; /* Check for console input */ hndl = NIL; if (console && cinput) break; /* Check timer every other time */ ms2 = 0; if (console) toggle ^= 1; if (toggle || !console) { ms2 = timer_fire(); if ((hndl = ev_peek())) break; } /* Really wait */ n = 0; for (src=sources; src; src=src->next) if (src->fd>0 && n<MAXFDS) sourcefds[n++] = src->fd; call_bwait(); cinput = os_wait(n, sourcefds, console, (ms1<ms2) ? ms1 : ms2 ); } unblock_async_poll(); LOCK(hndl); return hndl; }