libstore: make Worker::waitForBuildSlot private

Change-Id: I02a54846cd65622edbd7a1d6c24a623b4a59e5b3
This commit is contained in:
eldritch horrors 2024-08-02 17:00:57 +02:00
parent 6fdb47f0b2
commit b33c969519
6 changed files with 12 additions and 13 deletions

View file

@ -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 =

View file

@ -106,12 +106,13 @@ struct Goal : public std::enable_shared_from_this<Goal>
public:
struct [[nodiscard]] StillAlive {};
struct [[nodiscard]] WaitForSlot {};
struct [[nodiscard]] Finished {
ExitCode result;
std::unique_ptr<Error> ex;
};
struct [[nodiscard]] WorkResult : std::variant<StillAlive, Finished>
struct [[nodiscard]] WorkResult : std::variant<StillAlive, WaitForSlot, Finished>
{
WorkResult() = delete;
using variant::variant;

View file

@ -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);

View file

@ -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<MaintainCount<uint64_t>>(worker.runningSubstitutions);

View file

@ -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

View file

@ -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