From d46b9ff9be0f0316d53339f55773be22ace25273 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sat, 25 Jul 2020 20:31:44 -0500 Subject: [PATCH] Remove repeated acquire of disowned pid lock in a loop --- src/proc.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/proc.cpp b/src/proc.cpp index 268ae2224..9ab2ceb43 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -329,18 +329,19 @@ static owning_lock> s_disowned_pids; void add_disowned_job(job_t *j) { if (j == nullptr) return; - // NEVER add our own (or an invalid) pgid as they are not unique to only + // Never add our own (or an invalid) pgid as it is not unique to only // one job, and may result in a deadlock if we attempt the wait. auto pgid = j->get_pgid(); + auto disowned_pids = s_disowned_pids.acquire(); if (pgid && *pgid != getpgrp() && *pgid > 0) { // waitpid(2) is signalled to wait on a process group rather than a // process id by using the negative of its value. - s_disowned_pids.acquire()->push_back(*pgid * -1); + disowned_pids->push_back(*pgid * -1); } else { // Instead, add the PIDs of any external processes for (auto &process : j->processes) { if (process->pid) { - s_disowned_pids.acquire()->push_back(process->pid); + disowned_pids->push_back(process->pid); } } }