add a sleep to avoid busy work when the scheduler isn't loaded and we block on an output port

This commit is contained in:
Alex Shinn 2012-08-25 13:37:30 +09:00
parent 4bd428da9e
commit b31b52909e

8
vm.c
View file

@ -1967,7 +1967,7 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) {
#endif #endif
i = sexp_write_string_n(ctx, sexp_bytes_data(tmp1), sexp_unbox_fixnum(_ARG2), _ARG3); i = sexp_write_string_n(ctx, sexp_bytes_data(tmp1), sexp_unbox_fixnum(_ARG2), _ARG3);
#if SEXP_USE_GREEN_THREADS #if SEXP_USE_GREEN_THREADS
if (i < sexp_unbox_fixnum(_ARG2)) { if (i < sexp_unbox_fixnum(_ARG2) && errno == EAGAIN) {
if (sexp_port_stream(_ARG3)) clearerr(sexp_port_stream(_ARG3)); if (sexp_port_stream(_ARG3)) clearerr(sexp_port_stream(_ARG3));
/* modify stack in-place so we continue where we left off next time */ /* modify stack in-place so we continue where we left off next time */
if (i > 0) { if (i > 0) {
@ -1978,10 +1978,12 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) {
_ARG2 = sexp_make_fixnum(sexp_unbox_fixnum(_ARG2) - i); _ARG2 = sexp_make_fixnum(sexp_unbox_fixnum(_ARG2) - i);
} }
/* yield if threads are enabled (otherwise busy loop) */ /* yield if threads are enabled (otherwise busy loop) */
if (sexp_applicablep(sexp_global(ctx, SEXP_G_THREADS_BLOCKER))) { /* TODO: the wait seems necessary on OS X to stop a print loop to ptys */
if (sexp_applicablep(sexp_global(ctx, SEXP_G_THREADS_BLOCKER)))
sexp_apply1(ctx, sexp_global(ctx, SEXP_G_THREADS_BLOCKER), _ARG3); sexp_apply1(ctx, sexp_global(ctx, SEXP_G_THREADS_BLOCKER), _ARG3);
else /* no scheduler but output full, wait 5ms */
usleep(5*1000);
fuel = 0; fuel = 0;
}
ip--; /* try again */ ip--; /* try again */
goto loop; goto loop;
} }