From 733b716783d512e5bde7891b793d032d1ee7500a Mon Sep 17 00:00:00 2001 From: "K. Noel Belcourt" Date: Tue, 25 Sep 2007 23:11:12 +0000 Subject: [PATCH] Add macros to gcc.hpp to support pathscale toolset. Added an optimization to the -lx unix timeout code. I compute the amount of time the select call should sleep until the "oldest" process times out. This ensures that all processes that timeout will be killed within one second of their expiration. [SVN r39534] --- historic/jam/src/execunix.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/historic/jam/src/execunix.c b/historic/jam/src/execunix.c index 201698a1f..17880cd91 100644 --- a/historic/jam/src/execunix.c +++ b/historic/jam/src/execunix.c @@ -62,6 +62,7 @@ static clock_t tps = 0; static struct timeval tv; +static int timeout = 0; static int intr = 0; static int cmdsrunning = 0; @@ -355,6 +356,9 @@ void close_streams(int i, int s) void populate_file_descriptors(int *fmax, fd_set *fds) { int i, fd_max = 0; + struct tms buf; + clock_t current = times(&buf); + timeout = globs.timeout; /* compute max read file descriptor for use in select */ FD_ZERO(fds); @@ -375,9 +379,9 @@ void populate_file_descriptors(int *fmax, fd_set *fds) } if (globs.timeout && cmdtab[i].pid) { - struct tms buf; - clock_t current = times(&buf); - if (globs.timeout <= (current-cmdtab[i].start_time)/tps) { + clock_t consumed = (current - cmdtab[i].start_time) / tps; + timeout = (globs.timeout - consumed) < timeout ? (globs.timeout - consumed) : timeout; + if (globs.timeout <= consumed) { killpg(cmdtab[i].pid, SIGKILL); cmdtab[i].exit_reason = EXIT_TIMEOUT; } @@ -414,7 +418,7 @@ execwait() if (0 < globs.timeout) { /* force select to timeout so we can terminate expired processes */ - tv.tv_sec = globs.timeout; + tv.tv_sec = timeout; tv.tv_usec = 0; /* select will wait until: io on a descriptor, a signal, or we time out */