libstore: make Worker::waitForAWhile private

Change-Id: I0cdcd436ee71124ca992b4f4fe307624a25f11e9
This commit is contained in:
eldritch horrors 2024-08-02 17:00:57 +02:00
parent b33c969519
commit 3ecb46e3e7
5 changed files with 14 additions and 15 deletions

View file

@ -701,8 +701,7 @@ Goal::WorkResult DerivationGoal::tryToBuild()
if (!actLock)
actLock = std::make_unique<Activity>(*logger, lvlWarn, actBuildWaiting,
fmt("waiting for lock on %s", Magenta(showPaths(lockFiles))));
worker.waitForAWhile(shared_from_this());
return StillAlive{};
return WaitForAWhile{};
}
actLock.reset();
@ -753,9 +752,8 @@ Goal::WorkResult DerivationGoal::tryToBuild()
if (!actLock)
actLock = std::make_unique<Activity>(*logger, lvlTalkative, actBuildWaiting,
fmt("waiting for a machine to build '%s'", Magenta(worker.store.printStorePath(drvPath))));
worker.waitForAWhile(shared_from_this());
outputLocks.unlock();
return StillAlive{};
return WaitForAWhile{};
case rpDecline:
/* We should do it ourselves. */
break;

View file

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

View file

@ -201,8 +201,7 @@ Goal::WorkResult LocalDerivationGoal::tryLocalBuild()
if (!actLock)
actLock = std::make_unique<Activity>(*logger, lvlWarn, actBuildWaiting,
fmt("waiting for a free build user ID for '%s'", Magenta(worker.store.printStorePath(drvPath))));
worker.waitForAWhile(shared_from_this());
return StillAlive{};
return WaitForAWhile{};
}
}

View file

@ -188,6 +188,7 @@ void Worker::handleWorkResult(GoalPtr goal, Goal::WorkResult how)
overloaded{
[&](Goal::StillAlive) {},
[&](Goal::WaitForSlot) { waitForBuildSlot(goal); },
[&](Goal::WaitForAWhile) { waitForAWhile(goal); },
[&](Goal::Finished & f) { goalFinished(goal, f); },
},
how

View file

@ -114,6 +114,14 @@ private:
*/
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
* polling is inefficient, but POSIX doesn't really provide a way
* to wait for multiple locks in the main select() loop.
*/
void waitForAWhile(GoalPtr goal);
public:
const Activity act;
@ -239,14 +247,6 @@ public:
*/
void childTerminated(Goal * goal);
/**
* Wait for a few seconds and then retry this goal. Used when
* waiting for a lock held by another process. This kind of
* polling is inefficient, but POSIX doesn't really provide a way
* to wait for multiple locks in the main select() loop.
*/
void waitForAWhile(GoalPtr goal);
/**
* Loop until the specified top-level goals have finished.
*/