From ebe2dc2766cff306f7e2d4b9ebfd851dba038f00 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 16 Feb 2019 17:35:16 -0800 Subject: [PATCH] Processes to record topic generations before execution The sigchld generation expresses the idea that, if we receive a sigchld signal, the generation will be different than when we last recorded it. A process cannot exit before it has launched, so check the generation count before process launch. This is an optimization that reduces failing waitpid calls. --- src/exec.cpp | 1 + src/proc.cpp | 6 +++++- src/proc.h | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/exec.cpp b/src/exec.cpp index bf311bb74..c9d662464 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -899,6 +899,7 @@ static bool exec_process_in_job(parser_t &parser, process_t *p, std::shared_ptr< } // Execute the process. + p->check_generations_before_launch(); switch (p->type) { case INTERNAL_FUNCTION: case INTERNAL_BLOCK_NODE: { diff --git a/src/proc.cpp b/src/proc.cpp index 0561a60d4..667d76ace 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -324,7 +324,11 @@ static void handle_child_status(pid_t pid, int status) { } } -process_t::process_t() {} +process_t::process_t() = default; + +void process_t::check_generations_before_launch() { + gens_ = topic_monitor_t::principal().current_generations(); +} job_t::job_t(job_id_t jobid, io_chain_t bio, std::shared_ptr parent) : block_io(std::move(bio)), diff --git a/src/proc.h b/src/proc.h index 170346ea1..7379bd065 100644 --- a/src/proc.h +++ b/src/proc.h @@ -113,6 +113,11 @@ class process_t { void set_io_chain(const io_chain_t &chain) { this->process_io_chain = chain; } + /// Store the current topic generations. That is, right before the process is launched, record + /// the generations of all topics; then we can tell which generation values have changed after + /// launch. This helps us avoid spurious waitpid calls. + void check_generations_before_launch(); + /// Actual command to pass to exec in case of EXTERNAL or INTERNAL_EXEC. wcstring actual_cmd;