diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-08-09 21:06:39 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-08-09 21:06:39 +0100 |
commit | 37982010caf2525c4bff372b43a3841be7b60225 (patch) | |
tree | 163e7062bbd5a5eb8c9dc90c2399af353eae3cc6 | |
parent | Update string literals in regex to behave predictably regardless of standard_... (diff) | |
download | gentoobrowse-api-37982010caf2525c4bff372b43a3841be7b60225.tar.bz2 gentoobrowse-api-37982010caf2525c4bff372b43a3841be7b60225.tar.xz gentoobrowse-api-37982010caf2525c4bff372b43a3841be7b60225.zip |
Fix race condition in building related maps
-rw-r--r-- | gentoobrowse-api/client/helpers.h | 16 | ||||
-rw-r--r-- | 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<typename Key, typename Target, typename Collection, typename Proxy> std::map<Key, Target> asyncMapRelated(const Collection & collection, Proxy p, Key Collection::value_type::element_type::* member, - Ice::AsyncResultPtr (Proxy::element_type::*f)(Key, - const ::IceInternal::Function<void (const Target &)> &response, - const ::IceInternal::Function<void (const ::Ice::Exception &)> &exception, - const ::IceInternal::Function<void (bool)> & )) + Ice::AsyncResultPtr (Proxy::element_type::*b)(Key), + Target (Proxy::element_type::*e)(const Ice::AsyncResultPtr &)) { std::map<Key, Target> rtn; std::map<Key, Ice::AsyncResultPtr> 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); |