From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id aOxTJQu8yF/cXAAA0tVLHw (envelope-from ) for ; Thu, 03 Dec 2020 10:20:59 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 2KcnIQu8yF+hKQAAB5/wlQ (envelope-from ) for ; Thu, 03 Dec 2020 10:20:59 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 60C2A9403E8 for ; Thu, 3 Dec 2020 10:20:59 +0000 (UTC) Received: from localhost ([::1]:53956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkljO-0005BI-Bl for larch@yhetil.org; Thu, 03 Dec 2020 05:20:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkliV-0004Pm-AI for guix-patches@gnu.org; Thu, 03 Dec 2020 05:20:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:55171) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kkliV-0006R7-3C for guix-patches@gnu.org; Thu, 03 Dec 2020 05:20:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kkliU-0000Fk-Vp for guix-patches@gnu.org; Thu, 03 Dec 2020 05:20:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#45018] [PATCH 3/6] daemon: Factorize substituter agent spawning. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 03 Dec 2020 10:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45018 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 45018@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 45018-submit@debbugs.gnu.org id=B45018.1606990795897 (code B ref 45018); Thu, 03 Dec 2020 10:20:02 +0000 Received: (at 45018) by debbugs.gnu.org; 3 Dec 2020 10:19:55 +0000 Received: from localhost ([127.0.0.1]:38472 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kkliM-0000EJ-P7 for submit@debbugs.gnu.org; Thu, 03 Dec 2020 05:19:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47606) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kkliL-0000Dm-HK for 45018@debbugs.gnu.org; Thu, 03 Dec 2020 05:19:53 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:40705) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkliG-0006Ik-Bk; Thu, 03 Dec 2020 05:19:48 -0500 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=49238 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kkliE-0007oh-TN; Thu, 03 Dec 2020 05:19:47 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Thu, 3 Dec 2020 11:19:27 +0100 Message-Id: <20201203101930.11210-3-ludo@gnu.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201203101930.11210-1-ludo@gnu.org> References: <20201203101930.11210-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 2.22 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 60C2A9403E8 X-Spam-Score: 2.22 X-Migadu-Scanner: ns3122888.ip-94-23-21.eu X-TUID: 7rxyw9AfNTBt * nix/libstore/local-store.hh (class LocalStore)[substituter]: New method. [runningSubstituter]: Turn into a shared_ptr. * nix/libstore/local-store.cc (LocalStore::querySubstitutablePaths): Call 'substituter' instead of using inline code. (LocalStore::querySubstitutablePathInfos): Likewise. (LocalStore::substituter): New method. --- nix/libstore/local-store.cc | 29 +++++++++++++---------------- nix/libstore/local-store.hh | 5 ++++- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/nix/libstore/local-store.cc b/nix/libstore/local-store.cc index c7df8da085..c304e2ddd1 100644 --- a/nix/libstore/local-store.cc +++ b/nix/libstore/local-store.cc @@ -850,14 +850,7 @@ PathSet LocalStore::querySubstitutablePaths(const PathSet & paths) if (!settings.useSubstitutes || paths.empty()) return res; - if (!runningSubstituter) { - const Strings args = { "substitute", "--query" }; - const std::map env = { { "_NIX_OPTIONS", settings.pack() } }; - std::unique_ptrfresh(new Agent(settings.guixProgram, args, env)); - runningSubstituter.swap(fresh); - } - - Agent & run = *runningSubstituter; + Agent & run = *substituter(); string s = "have "; foreach (PathSet::const_iterator, j, paths) @@ -877,18 +870,22 @@ PathSet LocalStore::querySubstitutablePaths(const PathSet & paths) } +std::shared_ptr LocalStore::substituter() +{ + if (!runningSubstituter) { + const Strings args = { "substitute", "--query" }; + const std::map env = { { "_NIX_OPTIONS", settings.pack() } }; + runningSubstituter = std::make_shared(settings.guixProgram, args, env); + } + + return runningSubstituter; +} + void LocalStore::querySubstitutablePathInfos(PathSet & paths, SubstitutablePathInfos & infos) { if (!settings.useSubstitutes) return; - if (!runningSubstituter) { - const Strings args = { "substitute", "--query" }; - const std::map env = { { "_NIX_OPTIONS", settings.pack() } }; - std::unique_ptrfresh(new Agent(settings.guixProgram, args, env)); - runningSubstituter.swap(fresh); - } - - Agent & run = *runningSubstituter; + Agent & run = *substituter(); string s = "info "; foreach (PathSet::const_iterator, i, paths) diff --git a/nix/libstore/local-store.hh b/nix/libstore/local-store.hh index 57d15bac7e..9ba37219da 100644 --- a/nix/libstore/local-store.hh +++ b/nix/libstore/local-store.hh @@ -42,7 +42,10 @@ class LocalStore : public StoreAPI { private: /* The currently running substituter or empty. */ - std::unique_ptr runningSubstituter; + std::shared_ptr runningSubstituter; + + /* Ensure the substituter is running and return it. */ + std::shared_ptr substituter(); Path linksDir; -- 2.29.2