In ok thread mode, use wait_util instead of wait_for.

wait_for(delta) is wait_until(steady_clock::now() + delta) under the
hood, so using wait_for() like this implies an extra call to now() that
we can avoid by using wait_until().

We can hoist that call out and just do it once...  the past stays the past.

This is not super important.  Just noticed while profiling.  It's nice
to keep the overhead of the ok tool down so the real work can show.  :)

Change-Id: I89d25a800b63ebcfc229b5b3aa3f2dd621f4e7b4
Reviewed-on: https://skia-review.googlesource.com/14480
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Herb Derby <herb@google.com>
This commit is contained in:
Mike Klein 2017-04-27 09:50:34 -04:00 committed by Skia Commit-Bot
parent b4bbc64ade
commit 9fa99614ec

View File

@ -119,6 +119,7 @@ struct SerialEngine : Engine {
struct ThreadEngine : Engine {
std::list<std::future<Status>> live;
const std::chrono::steady_clock::time_point the_past = std::chrono::steady_clock::now();
bool spawn(std::function<Status(void)> fn) override {
live.push_back(std::async(std::launch::async, fn));
@ -132,7 +133,7 @@ struct ThreadEngine : Engine {
for (;;) {
for (auto it = live.begin(); it != live.end(); it++) {
if (it->wait_for(std::chrono::seconds::zero()) == std::future_status::ready) {
if (it->wait_until(the_past) == std::future_status::ready) {
Status s = it->get();
live.erase(it);
return s;