diff --git a/lix/libutil/thread-pool.hh b/lix/libutil/thread-pool.hh index 0e35fb27e..bb090c00f 100644 --- a/lix/libutil/thread-pool.hh +++ b/lix/libutil/thread-pool.hh @@ -93,8 +93,8 @@ template void processGraph( const char *poolName, const std::set & nodes, - std::function(const T &)> getEdges, - std::function processNode) + std::function(AsyncIoRoot &, const T &)> getEdges, + std::function processNode) { struct Graph { std::set left; @@ -103,14 +103,14 @@ void processGraph( Sync graph_(Graph{nodes, {}, {}}); - std::function worker; + std::function worker; /* Create pool last to ensure threads are stopped before other destructors * run */ ThreadPool pool{poolName}; - worker = [&](const T & node) { + worker = [&](AsyncIoRoot & aio, const T & node) { { auto graph(graph_.lock()); @@ -122,7 +122,7 @@ void processGraph( getRefs: { - auto refs = getEdges(node); + auto refs = getEdges(aio, node); refs.erase(node); { @@ -140,7 +140,7 @@ void processGraph( return; doWork: - processNode(node); + processNode(aio, node); /* Enqueue work for all nodes that were waiting on this one and have no unprocessed dependencies. */ @@ -152,7 +152,7 @@ void processGraph( assert(i != refs.end()); refs.erase(i); if (refs.empty()) - pool.enqueue(std::bind(worker, rref)); + pool.enqueueWithAio(std::bind(worker, std::placeholders::_1, rref)); } graph->left.erase(node); graph->refs.erase(node); @@ -161,7 +161,7 @@ void processGraph( }; for (auto & node : nodes) - pool.enqueue(std::bind(worker, std::ref(node))); + pool.enqueueWithAio(std::bind(worker, std::placeholders::_1, std::ref(node))); pool.process(); @@ -169,4 +169,19 @@ void processGraph( throw Error("graph processing incomplete (cyclic reference?)"); } +template +void processGraph( + const char *poolName, + const std::set & nodes, + std::function(const T &)> getEdges, + std::function processNode) +{ + processGraph( + poolName, + nodes, + [&](AsyncIoRoot &, const T & node) { return getEdges(node); }, + [&](AsyncIoRoot &, const T & node) { processNode(node); } + ); +} + }