diff options
author | eldritch horrors <pennae@lix.systems> | 2024-09-24 00:21:16 +0200 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-09-27 16:40:27 +0200 |
commit | 852da07b67564f7a9986f0638aac391d334d4afa (patch) | |
tree | 993d896dd8353a664723206c2f3ea59230f3d1f5 /src/libstore/build/substitution-goal.cc | |
parent | bf32085d63ccfa8fb1e0cff2f2ae7156b4679015 (diff) |
libstore: replace Goal::WaitForSlot with semaphores
now that we have an event loop in the worker we can use it and its
magical execution suspending properties to replace the slot counts
we managed explicitly with semaphores and raii tokens. technically
this would not have needed an event loop base to be doable, but it
is a whole lot easier to wait for a token to be available if there
is a callback mechanism ready for use that doesn't require a whole
damn dedicated abstract method in Goal to work, and specific calls
to that dedicated method strewn all over the worker implementation
Change-Id: I1da7cf386d94e2bbf2dba9b53ff51dbce6a0cff7
Diffstat (limited to 'src/libstore/build/substitution-goal.cc')
-rw-r--r-- | src/libstore/build/substitution-goal.cc | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/libstore/build/substitution-goal.cc b/src/libstore/build/substitution-goal.cc index 058f858d4..6d90196fa 100644 --- a/src/libstore/build/substitution-goal.cc +++ b/src/libstore/build/substitution-goal.cc @@ -45,9 +45,9 @@ Goal::Finished PathSubstitutionGoal::done( } -kj::Promise<Result<Goal::WorkResult>> PathSubstitutionGoal::work(bool inBuildSlot) noexcept +kj::Promise<Result<Goal::WorkResult>> PathSubstitutionGoal::work() noexcept { - return (this->*state)(inBuildSlot); + return (this->*state)(slotToken.valid()); } @@ -203,7 +203,10 @@ try { trace("trying to run"); if (!inBuildSlot) { - return {WaitForSlot{}}; + return worker.substitutions.acquire().then([this](auto token) { + slotToken = std::move(token); + return work(); + }); } maintainRunningSubstitutions = worker.runningSubstitutions.addTemporarily(1); @@ -236,7 +239,7 @@ try { state = &PathSubstitutionGoal::finished; return {WaitForWorld{ - pipe.promise.then([]() -> Outcome<void, Finished> { return result::success(); }), true + pipe.promise.then([]() -> Outcome<void, Finished> { return result::success(); }) }}; } catch (...) { return {std::current_exception()}; @@ -248,6 +251,7 @@ try { trace("substitute finished"); try { + slotToken = {}; thr.get(); } catch (std::exception & e) { printError(e.what()); |