From b33c96951915ca702632b1d73dc6331f77d2bbea Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 2 Aug 2024 17:00:57 +0200 Subject: [PATCH] libstore: make Worker::waitForBuildSlot private Change-Id: I02a54846cd65622edbd7a1d6c24a623b4a59e5b3 --- src/libstore/build/drv-output-substitution-goal.cc | 3 +-- src/libstore/build/goal.hh | 3 ++- src/libstore/build/local-derivation-goal.cc | 3 +-- src/libstore/build/substitution-goal.cc | 3 +-- src/libstore/build/worker.cc | 1 + src/libstore/build/worker.hh | 12 ++++++------ 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/libstore/build/drv-output-substitution-goal.cc b/src/libstore/build/drv-output-substitution-goal.cc index 62e86e1cc..068f41a49 100644 --- a/src/libstore/build/drv-output-substitution-goal.cc +++ b/src/libstore/build/drv-output-substitution-goal.cc @@ -41,8 +41,7 @@ Goal::WorkResult DrvOutputSubstitutionGoal::tryNext() if maxSubstitutionJobs == 0, we still allow a substituter to run. This prevents infinite waiting. */ if (worker.runningSubstitutions >= std::max(1U, settings.maxSubstitutionJobs.get())) { - worker.waitForBuildSlot(shared_from_this()); - return StillAlive{}; + return WaitForSlot{}; } maintainRunningSubstitutions = diff --git a/src/libstore/build/goal.hh b/src/libstore/build/goal.hh index dd29b9fc4..bf3677bb2 100644 --- a/src/libstore/build/goal.hh +++ b/src/libstore/build/goal.hh @@ -106,12 +106,13 @@ struct Goal : public std::enable_shared_from_this public: struct [[nodiscard]] StillAlive {}; + struct [[nodiscard]] WaitForSlot {}; struct [[nodiscard]] Finished { ExitCode result; std::unique_ptr ex; }; - struct [[nodiscard]] WorkResult : std::variant + struct [[nodiscard]] WorkResult : std::variant { WorkResult() = delete; using variant::variant; diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc index db380e07c..975e21b49 100644 --- a/src/libstore/build/local-derivation-goal.cc +++ b/src/libstore/build/local-derivation-goal.cc @@ -158,9 +158,8 @@ Goal::WorkResult LocalDerivationGoal::tryLocalBuild() unsigned int curBuilds = worker.getNrLocalBuilds(); if (curBuilds >= settings.maxBuildJobs) { state = &DerivationGoal::tryToBuild; - worker.waitForBuildSlot(shared_from_this()); outputLocks.unlock(); - return StillAlive{}; + return WaitForSlot{}; } assert(derivationType); diff --git a/src/libstore/build/substitution-goal.cc b/src/libstore/build/substitution-goal.cc index fb2949fd0..192ddc572 100644 --- a/src/libstore/build/substitution-goal.cc +++ b/src/libstore/build/substitution-goal.cc @@ -194,8 +194,7 @@ Goal::WorkResult PathSubstitutionGoal::tryToRun() if maxSubstitutionJobs == 0, we still allow a substituter to run. This prevents infinite waiting. */ if (worker.getNrSubstitutions() >= std::max(1U, (unsigned int) settings.maxSubstitutionJobs)) { - worker.waitForBuildSlot(shared_from_this()); - return StillAlive{}; + return WaitForSlot{}; } maintainRunningSubstitutions = std::make_unique>(worker.runningSubstitutions); diff --git a/src/libstore/build/worker.cc b/src/libstore/build/worker.cc index 84727a377..46f1d50e6 100644 --- a/src/libstore/build/worker.cc +++ b/src/libstore/build/worker.cc @@ -187,6 +187,7 @@ void Worker::handleWorkResult(GoalPtr goal, Goal::WorkResult how) std::visit( overloaded{ [&](Goal::StillAlive) {}, + [&](Goal::WaitForSlot) { waitForBuildSlot(goal); }, [&](Goal::Finished & f) { goalFinished(goal, f); }, }, how diff --git a/src/libstore/build/worker.hh b/src/libstore/build/worker.hh index 5af93b49e..101e553fd 100644 --- a/src/libstore/build/worker.hh +++ b/src/libstore/build/worker.hh @@ -108,6 +108,12 @@ private: void goalFinished(GoalPtr goal, Goal::Finished & f); void handleWorkResult(GoalPtr goal, Goal::WorkResult how); + /** + * Put `goal` to sleep until a build slot becomes available (which + * might be right away). + */ + void waitForBuildSlot(GoalPtr goal); + public: const Activity act; @@ -233,12 +239,6 @@ public: */ void childTerminated(Goal * goal); - /** - * Put `goal` to sleep until a build slot becomes available (which - * might be right away). - */ - void waitForBuildSlot(GoalPtr goal); - /** * Wait for a few seconds and then retry this goal. Used when * waiting for a lock held by another process. This kind of