Module Name: src Committed By: sjg Date: Sun Jan 31 07:07:53 UTC 2021
Modified Files: src/usr.bin/make: job.c Log Message: Reduce unnecessary calls to waitpid Set a flag when we catch SIGCHLD and don't call waitpid if it is not set. Clear it when we call waitpid. To generate a diff of this commit: cvs rdiff -u -r1.404 -r1.405 src/usr.bin/make/job.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/job.c diff -u src/usr.bin/make/job.c:1.404 src/usr.bin/make/job.c:1.405 --- src/usr.bin/make/job.c:1.404 Sat Jan 30 13:12:00 2021 +++ src/usr.bin/make/job.c Sun Jan 31 07:07:53 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: job.c,v 1.404 2021/01/30 13:12:00 rillig Exp $ */ +/* $NetBSD: job.c,v 1.405 2021/01/31 07:07:53 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -143,7 +143,7 @@ #include "trace.h" /* "@(#)job.c 8.2 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: job.c,v 1.404 2021/01/30 13:12:00 rillig Exp $"); +MAKE_RCSID("$NetBSD: job.c,v 1.405 2021/01/31 07:07:53 sjg Exp $"); /* * A shell defines how the commands are run. All commands for a target are @@ -439,6 +439,7 @@ enum { }; static sigset_t caught_signals; /* Set of signals we handle */ +static volatile int caught_sigchld; static void JobDoOutput(Job *, Boolean); static void JobInterrupt(Boolean, int) MAKE_ATTR_DEAD; @@ -603,6 +604,7 @@ JobCondPassSig(int signo) static void JobChildSig(int signo MAKE_ATTR_UNUSED) { + caught_sigchld = 1; while (write(childExitJob.outPipe, CHILD_EXIT, 1) == -1 && errno == EAGAIN) continue; @@ -1972,6 +1974,11 @@ Job_CatchChildren(void) if (jobTokensRunning == 0) return; + /* Have we received SIGCHLD since last call? */ + if (caught_sigchld == 0) + return; + caught_sigchld = 0; + while ((pid = waitpid((pid_t)-1, &status, WNOHANG | WUNTRACED)) > 0) { DEBUG2(JOB, "Process %d exited/stopped status %x.\n", pid, status); @@ -2206,6 +2213,7 @@ Job_Init(void) memset(job_table, 0, (size_t)opts.maxJobs * sizeof *job_table); job_table_end = job_table + opts.maxJobs; wantToken = 0; + caught_sigchld = 0; aborting = ABORT_NONE; job_errors = 0;