From 772ff6f1f1d8d98f33666179b074f5539ab873b9 Mon Sep 17 00:00:00 2001 From: Eugene Zhuk Date: Mon, 20 Jan 2014 23:18:25 -0800 Subject: [PATCH] [#4] Cleaned up FastClock background thread. --- src/benchmark.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/benchmark.cc b/src/benchmark.cc index 9e68436c..b33f1c9b 100644 --- a/src/benchmark.cc +++ b/src/benchmark.cc @@ -509,7 +509,9 @@ class State::FastClock { } void BGThread() { - do { + mutex_lock l(&bg_mutex_); + while (!bg_done_) + { struct timeval tv; gettimeofday(&tv, nullptr); @@ -523,13 +525,12 @@ class State::FastClock { ts.tv_nsec %= kNumNanosPerSecond; // NOTE: this should probably be platform specific. - mutex_lock l(&bg_mutex_); pthread_cond_timedwait(&bg_cond_, &bg_mutex_, &ts); std::atomic_store(&approx_time_, NowMicros()); // NOTE: same code but no memory barrier. think on it. // base::subtle::Release_Store(&approx_time_, NowMicros()); - } while (!bg_done_); + } } DISALLOW_COPY_AND_ASSIGN(FastClock)