aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-07-20 21:05:19 +0200
committereldritch horrors <pennae@lix.systems>2024-07-22 19:01:40 +0000
commit58a91d70c9c6f22bbb5425f1e9973befe3fdebfb (patch)
tree001e6d080fa4fb3964ce9f6421078382e5b1e3b7 /src
parentad36fb43ada8b4b31a10f6a7e1bade9f00aaa661 (diff)
libstore: use std::async instead of Goal threads
the goals are either already using std::async and merely forgot to remove std::thread vestiges or they emulate async with threads and promises. we can simply use async directly everywhere for clarity. Change-Id: I3f05098310a25984f10fff1e68c573329002b500
Diffstat (limited to 'src')
-rw-r--r--src/libstore/build/drv-output-substitution-goal.hh6
-rw-r--r--src/libstore/build/substitution-goal.cc19
-rw-r--r--src/libstore/build/substitution-goal.hh4
3 files changed, 7 insertions, 22 deletions
diff --git a/src/libstore/build/drv-output-substitution-goal.hh b/src/libstore/build/drv-output-substitution-goal.hh
index 008b211a1..47b9ecc49 100644
--- a/src/libstore/build/drv-output-substitution-goal.hh
+++ b/src/libstore/build/drv-output-substitution-goal.hh
@@ -4,7 +4,6 @@
#include "store-api.hh"
#include "goal.hh"
#include "realisation.hh"
-#include <thread>
#include <future>
namespace nix {
@@ -41,11 +40,6 @@ class DrvOutputSubstitutionGoal : public Goal {
*/
std::shared_ptr<Store> sub;
- /**
- * The substituter thread.
- */
- std::thread thr;
-
std::unique_ptr<MaintainCount<uint64_t>> maintainRunningSubstitutions;
struct DownloadState
diff --git a/src/libstore/build/substitution-goal.cc b/src/libstore/build/substitution-goal.cc
index cc4cb3c8c..1330f061c 100644
--- a/src/libstore/build/substitution-goal.cc
+++ b/src/libstore/build/substitution-goal.cc
@@ -214,9 +214,7 @@ void PathSubstitutionGoal::tryToRun()
outPipe.create();
- promise = std::promise<void>();
-
- thr = std::thread([this]() {
+ thr = std::async(std::launch::async, [this]() {
auto & fetchPath = subPath ? *subPath : storePath;
try {
ReceiveInterrupts receiveInterrupts;
@@ -230,16 +228,12 @@ void PathSubstitutionGoal::tryToRun()
copyStorePath(
*sub, worker.store, fetchPath, repair, sub->isTrusted ? NoCheckSigs : CheckSigs
);
-
- promise.set_value();
} catch (const EndOfFile &) {
- promise.set_exception(std::make_exception_ptr(EndOfFile(
+ throw EndOfFile(
"NAR for '%s' fetched from '%s' is incomplete",
sub->printStorePath(fetchPath),
sub->getUri()
- )));
- } catch (...) {
- promise.set_exception(std::current_exception());
+ );
}
});
@@ -253,11 +247,10 @@ void PathSubstitutionGoal::finished()
{
trace("substitute finished");
- thr.join();
worker.childTerminated(this);
try {
- promise.get_future().get();
+ thr.get();
} catch (std::exception & e) {
printError(e.what());
@@ -316,9 +309,9 @@ void PathSubstitutionGoal::handleEOF(int fd)
void PathSubstitutionGoal::cleanup()
{
try {
- if (thr.joinable()) {
+ if (thr.valid()) {
// FIXME: signal worker thread to quit.
- thr.join();
+ thr.get();
worker.childTerminated(this);
}
diff --git a/src/libstore/build/substitution-goal.hh b/src/libstore/build/substitution-goal.hh
index 1d389d328..52780a967 100644
--- a/src/libstore/build/substitution-goal.hh
+++ b/src/libstore/build/substitution-goal.hh
@@ -50,9 +50,7 @@ struct PathSubstitutionGoal : public Goal
/**
* The substituter thread.
*/
- std::thread thr;
-
- std::promise<void> promise;
+ std::future<void> thr;
/**
* Whether to try to repair a valid path.