simplify collector function
looks like the lambda doesn't buy us anything here.
This commit is contained in:
parent
97dd8023e8
commit
b24c03e2de
|
@ -119,9 +119,7 @@ void handleBrokenWorkerPipe(Proc &proc) {
|
|||
}
|
||||
}
|
||||
|
||||
std::function<void()> collector(Sync<State> &state_,
|
||||
std::condition_variable &wakeup) {
|
||||
return [&]() {
|
||||
void collector(Sync<State> &state_, std::condition_variable &wakeup) {
|
||||
try {
|
||||
std::optional<std::unique_ptr<Proc>> proc_;
|
||||
std::optional<std::unique_ptr<LineReader>> fromReader_;
|
||||
|
@ -129,8 +127,8 @@ std::function<void()> collector(Sync<State> &state_,
|
|||
while (true) {
|
||||
if (!proc_.has_value()) {
|
||||
proc_ = std::make_unique<Proc>(worker);
|
||||
fromReader_ = std::make_unique<LineReader>(
|
||||
proc_.value()->from.release());
|
||||
fromReader_ =
|
||||
std::make_unique<LineReader>(proc_.value()->from.release());
|
||||
}
|
||||
auto proc = std::move(proc_.value());
|
||||
auto fromReader = std::move(fromReader_.value());
|
||||
|
@ -146,11 +144,9 @@ std::function<void()> collector(Sync<State> &state_,
|
|||
} else if (s != "next") {
|
||||
try {
|
||||
auto json = json::parse(s);
|
||||
throw Error("worker error: %s",
|
||||
(std::string)json["error"]);
|
||||
throw Error("worker error: %s", (std::string)json["error"]);
|
||||
} catch (const json::exception &e) {
|
||||
throw Error(
|
||||
"Received invalid JSON from worker: %s '%s'",
|
||||
throw Error("Received invalid JSON from worker: %s '%s'",
|
||||
e.what(), s);
|
||||
}
|
||||
}
|
||||
|
@ -226,10 +222,10 @@ std::function<void()> collector(Sync<State> &state_,
|
|||
state->exc = std::current_exception();
|
||||
wakeup.notify_all();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
/* Prevent undeclared dependencies in the evaluation via
|
||||
$NIX_PATH. */
|
||||
unsetenv("NIX_PATH");
|
||||
|
@ -277,8 +273,9 @@ int main(int argc, char **argv) {
|
|||
/* Start a collector thread per worker process. */
|
||||
std::vector<std::thread> threads;
|
||||
std::condition_variable wakeup;
|
||||
for (size_t i = 0; i < myArgs.nrWorkers; i++)
|
||||
threads.emplace_back(std::thread(collector(state_, wakeup)));
|
||||
for (size_t i = 0; i < myArgs.nrWorkers; i++) {
|
||||
threads.emplace_back(collector, std::ref(state_), std::ref(wakeup));
|
||||
}
|
||||
|
||||
for (auto &thread : threads)
|
||||
thread.join();
|
||||
|
|
Loading…
Reference in a new issue