Commit 772ff6f1 by Eugene Zhuk

[#4] Cleaned up FastClock background thread.

parent ceea4cb3
...@@ -509,7 +509,9 @@ class State::FastClock { ...@@ -509,7 +509,9 @@ class State::FastClock {
} }
void BGThread() { void BGThread() {
do { mutex_lock l(&bg_mutex_);
while (!bg_done_)
{
struct timeval tv; struct timeval tv;
gettimeofday(&tv, nullptr); gettimeofday(&tv, nullptr);
...@@ -523,13 +525,12 @@ class State::FastClock { ...@@ -523,13 +525,12 @@ class State::FastClock {
ts.tv_nsec %= kNumNanosPerSecond; ts.tv_nsec %= kNumNanosPerSecond;
// NOTE: this should probably be platform specific. // NOTE: this should probably be platform specific.
mutex_lock l(&bg_mutex_);
pthread_cond_timedwait(&bg_cond_, &bg_mutex_, &ts); pthread_cond_timedwait(&bg_cond_, &bg_mutex_, &ts);
std::atomic_store(&approx_time_, NowMicros()); std::atomic_store(&approx_time_, NowMicros());
// NOTE: same code but no memory barrier. think on it. // NOTE: same code but no memory barrier. think on it.
// base::subtle::Release_Store(&approx_time_, NowMicros()); // base::subtle::Release_Store(&approx_time_, NowMicros());
} while (!bg_done_); }
} }
DISALLOW_COPY_AND_ASSIGN(FastClock) DISALLOW_COPY_AND_ASSIGN(FastClock)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment