aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/misc.cc
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-04-27 01:02:22 +0200
committereldritch horrors <pennae@lix.systems>2024-05-07 14:35:20 +0000
commit964ac8b0e88fb5789b87e33273e42363958d0afb (patch)
treea205072edf06b023d82e77d06f3e463c5169fc4b /src/libstore/misc.cc
parent230860dbb8fc061fd55b98cedd134cdc5097ea69 (diff)
libutil: de-callback-ify computeClosure
only two users of this function exist. only one used it in a way that even bears resemblance to asynchronicity, and even that one didn't do it right. fully async and parallel computation would have only worked if any getEdgesAsync never calls the continuation it receives itself, only from more derived callbacks running on other threads. calling it directly would cause the decoupling promise to be awaited immediately *on the original thread*, completely negating all nice async effects. Change-Id: I0aa640950cf327533a32dee410105efdabb448df
Diffstat (limited to 'src/libstore/misc.cc')
-rw-r--r--src/libstore/misc.cc32
1 files changed, 8 insertions, 24 deletions
diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc
index c8646083b..22f6b67ee 100644
--- a/src/libstore/misc.cc
+++ b/src/libstore/misc.cc
@@ -14,10 +14,9 @@ namespace nix {
void Store::computeFSClosure(const StorePathSet & startPaths,
StorePathSet & paths_, bool flipDirection, bool includeOutputs, bool includeDerivers)
{
- std::function<std::set<StorePath>(const StorePath & path, std::future<ref<const ValidPathInfo>> &)> queryDeps;
+ std::function<std::set<StorePath>(const StorePath & path, ref<const ValidPathInfo>)> queryDeps;
if (flipDirection)
- queryDeps = [&](const StorePath& path,
- std::future<ref<const ValidPathInfo>> & fut) {
+ queryDeps = [&](const StorePath& path, ref<const ValidPathInfo>) {
StorePathSet res;
StorePathSet referrers;
queryReferrers(path, referrers);
@@ -36,10 +35,8 @@ void Store::computeFSClosure(const StorePathSet & startPaths,
return res;
};
else
- queryDeps = [&](const StorePath& path,
- std::future<ref<const ValidPathInfo>> & fut) {
+ queryDeps = [&](const StorePath& path, ref<const ValidPathInfo> info) {
StorePathSet res;
- auto info = fut.get();
for (auto& ref : info->references)
if (ref != path)
res.insert(ref);
@@ -54,24 +51,11 @@ void Store::computeFSClosure(const StorePathSet & startPaths,
return res;
};
- computeClosure<StorePath>(
- startPaths, paths_,
- [&](const StorePath& path,
- std::function<void(std::promise<std::set<StorePath>>&)>
- processEdges) {
- std::promise<std::set<StorePath>> promise;
- std::function<void(std::future<ref<const ValidPathInfo>>)>
- getDependencies =
- [&](std::future<ref<const ValidPathInfo>> fut) {
- try {
- promise.set_value(queryDeps(path, fut));
- } catch (...) {
- promise.set_exception(std::current_exception());
- }
- };
- queryPathInfo(path, getDependencies);
- processEdges(promise);
- });
+ paths_.merge(computeClosure<StorePath>(
+ startPaths,
+ [&](const StorePath& path) -> std::set<StorePath> {
+ return queryDeps(path, queryPathInfo(path));
+ }));
}
void Store::computeFSClosure(const StorePath & startPath,