Unblock the current thread if it was waiting on an fd with activity.

Prevents useless extra polling slowing down the process as noted in issue #144.
This commit is contained in:
Alex Shinn 2012-08-25 12:49:34 +09:00
parent 512c9032d3
commit 4bd428da9e

View file

@ -429,6 +429,15 @@ sexp sexp_scheduler (sexp ctx, sexp self, sexp_sint_t n, sexp root_thread) {
for (i=sexp_pollfds_num_fds(pollfds)-1; i>=0 && k>0; --i) { for (i=sexp_pollfds_num_fds(pollfds)-1; i>=0 && k>0; --i) {
if (pfds[i].revents > 0) { /* free all threads blocked on this fd */ if (pfds[i].revents > 0) { /* free all threads blocked on this fd */
k--; k--;
/* maybe unblock the current thread */
evt = sexp_context_event(ctx);
if ((sexp_portp(evt) && (sexp_port_fileno(evt) == pfds[i].fd))
|| (sexp_fixnump(evt) && (sexp_unbox_fixnum(evt) == pfds[i].fd))) {
sexp_context_waitp(ctx) = 0;
sexp_context_timeoutp(ctx) = 0;
sexp_context_event(ctx) = SEXP_FALSE;
}
/* maybe unblock paused threads */
for (ls1=SEXP_NULL, ls2=paused; sexp_pairp(ls2); ) { for (ls1=SEXP_NULL, ls2=paused; sexp_pairp(ls2); ) {
/* TODO: distinguish input and output on the same fd? */ /* TODO: distinguish input and output on the same fd? */
evt = sexp_context_event(sexp_car(ls2)); evt = sexp_context_event(sexp_car(ls2));
@ -436,6 +445,7 @@ sexp sexp_scheduler (sexp ctx, sexp self, sexp_sint_t n, sexp root_thread) {
|| (sexp_fixnump(evt) && sexp_unbox_fixnum(evt) == pfds[i].fd)) { || (sexp_fixnump(evt) && sexp_unbox_fixnum(evt) == pfds[i].fd)) {
sexp_context_waitp(sexp_car(ls2)) = 0; sexp_context_waitp(sexp_car(ls2)) = 0;
sexp_context_timeoutp(sexp_car(ls2)) = 0; sexp_context_timeoutp(sexp_car(ls2)) = 0;
sexp_context_event(sexp_car(ls2)) = SEXP_FALSE;
if (ls1==SEXP_NULL) if (ls1==SEXP_NULL)
sexp_global(ctx, SEXP_G_THREADS_PAUSED) = paused = sexp_cdr(ls2); sexp_global(ctx, SEXP_G_THREADS_PAUSED) = paused = sexp_cdr(ls2);
else else