aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2017-03-23 15:29:26 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-23 20:41:20 +0000
commit9827256c8a4fb10e58e68393b5d8d0b5cca71d70 (patch)
tree9ad29fa29659aa5e5d919e263a671509fdbc615b /tools
parente2dad1081cf4ad93a7466aaa2e3568da62abd94a (diff)
Improve TaskEngine::wait_one().
This runs much faster. Very good idea. Change-Id: I088aa9588c069a17e4745be55c2397114ee8a2bc Reviewed-on: https://skia-review.googlesource.com/10053 Reviewed-by: Herb Derby <herb@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/ok.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/tools/ok.cpp b/tools/ok.cpp
index 75c32730df..d0d3960afe 100644
--- a/tools/ok.cpp
+++ b/tools/ok.cpp
@@ -14,9 +14,10 @@
#include "SkPicture.h"
#include "SkSurface.h"
#include "gm.h"
-#include <deque>
+#include <chrono>
#include <functional>
#include <future>
+#include <list>
#include <map>
#include <memory>
#include <regex>
@@ -49,7 +50,7 @@ struct SerialEngine : Engine {
};
struct ThreadEngine : Engine {
- std::deque<std::future<Status>> live;
+ std::list<std::future<Status>> live;
bool spawn(std::function<Status(void)> fn) override {
live.push_back(std::async(std::launch::async, fn));
@@ -60,9 +61,16 @@ struct ThreadEngine : Engine {
if (live.empty()) {
return Status::None;
}
- Status s = live.front().get();
- live.pop_front();
- return s;
+
+ for (;;) {
+ for (auto it = live.begin(); it != live.end(); it++) {
+ if (it->wait_for(std::chrono::seconds::zero()) == std::future_status::ready) {
+ Status s = it->get();
+ live.erase(it);
+ return s;
+ }
+ }
+ }
}
};