mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-18 21:29:19 +02:00
limit waiting in thread scheduler to 10ms
This commit is contained in:
parent
e8c10ce259
commit
5f428d1299
1 changed files with 4 additions and 1 deletions
|
@ -592,6 +592,8 @@ sexp sexp_scheduler (sexp ctx, sexp self, sexp_sint_t n, sexp root_thread) {
|
|||
|
||||
if (sexp_context_waitp(res)) {
|
||||
/* the only thread available was waiting */
|
||||
/* TODO: if another thread is blocked on I/O, wait on that with
|
||||
* the appropriate minimum timeout */
|
||||
if (sexp_pairp(paused)
|
||||
&& sexp_context_before(sexp_car(paused), sexp_context_timeval(res))) {
|
||||
tmp = res;
|
||||
|
@ -609,13 +611,14 @@ sexp sexp_scheduler (sexp ctx, sexp self, sexp_sint_t n, sexp root_thread) {
|
|||
/* no timeout, wait for default 10ms */
|
||||
usecs = 10*1000;
|
||||
} else {
|
||||
/* wait until the next timeout */
|
||||
/* wait until the next timeout, or at most 10ms */
|
||||
gettimeofday(&tval, NULL);
|
||||
if (tval.tv_sec <= sexp_context_timeval(res).tv_sec) {
|
||||
usecs = (sexp_context_timeval(res).tv_sec - tval.tv_sec) * 1000000;
|
||||
if (tval.tv_usec < sexp_context_timeval(res).tv_usec || usecs > 0)
|
||||
usecs += sexp_context_timeval(res).tv_usec - tval.tv_usec;
|
||||
}
|
||||
if (usecs > 10*1000) usecs = 10*1000;
|
||||
}
|
||||
/* take a nap to avoid busy looping */
|
||||
usleep(usecs);
|
||||
|
|
Loading…
Add table
Reference in a new issue