diff -r 663b16a373e5 bmake/job.c --- a/bmake/job.c Sun Apr 15 11:34:25 2018 -0700 +++ b/bmake/job.c Fri May 11 17:03:17 2018 -0700 @@ -318,7 +318,6 @@ STATIC Job *job_table; /* The structures that describe them */ STATIC Job *job_table_end; /* job_table + maxJobs */ -static int wantToken; /* we want a token */ static int lurking_children = 0; static int make_suspended = 0; /* non-zero if we've seen a SIGTSTP (etc) */ @@ -2110,7 +2109,7 @@ /* The first fd in the list is the job token pipe */ do { - nready = poll(fds + 1 - wantToken, nfds - 1 + wantToken, POLL_MSEC); + nready = poll(fds, nfds, POLL_MSEC); } while (nready < 0 && errno == EINTR); if (nready < 0) @@ -2262,7 +2261,6 @@ job_table = bmake_malloc(maxJobs * sizeof *job_table); memset(job_table, 0, maxJobs * sizeof *job_table); job_table_end = job_table + maxJobs; - wantToken = 0; aborting = 0; errors = 0; @@ -2294,8 +2292,7 @@ fds = bmake_malloc(sizeof (*fds) * (2 + maxJobs)); jobfds = bmake_malloc(sizeof (*jobfds) * (2 + maxJobs)); - /* These are permanent entries and take slots 0 and 1 */ - watchfd(&tokenWaitJob); + /* Permanent entry */ watchfd(&childExitJob); sigemptyset(&caught_signals); @@ -2939,8 +2936,7 @@ * is currently empty. * * Side Effects: - * If pool is empty, set wantToken so that we wake up - * when a token is released. + * If pool is empty and no jobs running; sleep a bit. * *----------------------------------------------------------------------- */ @@ -2952,7 +2948,6 @@ char tok, tok1; int count; - wantToken = 0; if (DEBUG(JOB)) fprintf(debug_file, "Job_TokenWithdraw(%d): aborting %d, running %d\n", getpid(), aborting, jobTokensRunning); @@ -2963,14 +2958,16 @@ count = read(tokenWaitJob.inPipe, &tok, 1); if (count == 0) Fatal("eof on job pipe!"); - if (count < 0 && jobTokensRunning != 0) { + if (count < 0) { if (errno != EAGAIN) { Fatal("job pipe read: %s", strerror(errno)); } if (DEBUG(JOB)) fprintf(debug_file, "(%d) blocked for token\n", getpid()); - wantToken = 1; - return FALSE; + if (!jobTokensRunning) + sleep(1); /* avoid busy wait */ + else + return FALSE; } if (count == 1 && tok != '+') {