From 37982010caf2525c4bff372b43a3841be7b60225 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 9 Aug 2016 21:06:39 +0100 Subject: Fix race condition in building related maps --- gentoobrowse-api/client/helpers.h | 16 ++++------------ gentoobrowse-api/client/search.cpp | 3 ++- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/gentoobrowse-api/client/helpers.h b/gentoobrowse-api/client/helpers.h index 5221910..859be3f 100644 --- a/gentoobrowse-api/client/helpers.h +++ b/gentoobrowse-api/client/helpers.h @@ -9,27 +9,19 @@ template std::map asyncMapRelated(const Collection & collection, Proxy p, Key Collection::value_type::element_type::* member, - Ice::AsyncResultPtr (Proxy::element_type::*f)(Key, - const ::IceInternal::Function &response, - const ::IceInternal::Function &exception, - const ::IceInternal::Function & )) + Ice::AsyncResultPtr (Proxy::element_type::*b)(Key), + Target (Proxy::element_type::*e)(const Ice::AsyncResultPtr &)) { std::map rtn; std::map jobs; - std::mutex m; for (const auto & item : collection) { Key v = item.get()->*member; if (jobs.find(v) == jobs.end()) { - jobs.insert({ v, (p.get()->*f)(v, [&rtn, v, &m](const Target & t) { - m.lock(); - rtn.insert({v, t}); - m.unlock(); - }, [](const ::Ice::Exception & ex) { throw ex; } , nullptr) - }); + jobs.insert({ v, (p.get()->*b)(v) }); } } for (const auto & j : jobs) { - j.second->waitForCompleted(); + rtn.insert({ j.first, (p.get()->*e)(j.second) }); } return rtn; } diff --git a/gentoobrowse-api/client/search.cpp b/gentoobrowse-api/client/search.cpp index 7ec91be..29d16e2 100644 --- a/gentoobrowse-api/client/search.cpp +++ b/gentoobrowse-api/client/search.cpp @@ -10,7 +10,8 @@ class search : public Module { { auto pkgs = p->getPackagesSearch(boost::algorithm::join(a, " ")); auto cats = asyncMapRelated(pkgs, p, &Gentoo::Package::categoryid, - &IceProxy::Gentoo::Portage::begin_getCategory); + &IceProxy::Gentoo::Portage::begin_getCategory, + &IceProxy::Gentoo::Portage::end_getCategory); fprintbf(stdout, "Found %d packages:\n", pkgs.size()); for (const auto & pkg : pkgs) { fprintbf(stdout, "%s / %s\n\t%s\n", cats[pkg->categoryid]->name, pkg->name, pkg->description); -- cgit v1.2.3