Chromium Code Reviews| Index: base/debug/trace_event_impl.cc |
| diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc |
| index 9ee9fc802be105ea979576ec239c6275c467a7fc..71b5fbf6a243268120dfde53272cc2639eacb023 100644 |
| --- a/base/debug/trace_event_impl.cc |
| +++ b/base/debug/trace_event_impl.cc |
| @@ -716,6 +716,7 @@ class TraceSamplingThread : public PlatformThread::Delegate { |
| const char** category, |
| const char** name); |
| std::vector<TraceBucketData> sample_buckets_; |
| + Lock lock_; |
| bool thread_running_; |
| scoped_ptr<CancellationFlag> cancellation_flag_; |
| scoped_ptr<WaitableEvent> waitable_event_for_testing_; |
| @@ -724,6 +725,7 @@ class TraceSamplingThread : public PlatformThread::Delegate { |
| TraceSamplingThread::TraceSamplingThread() |
| : thread_running_(false) { |
| + AutoLock lock(lock_); |
| cancellation_flag_.reset(new CancellationFlag); |
| } |
| @@ -734,10 +736,14 @@ void TraceSamplingThread::ThreadMain() { |
| PlatformThread::SetName("Sampling Thread"); |
| thread_running_ = true; |
| const int kSamplingFrequencyMicroseconds = 1000; |
| - while (!cancellation_flag_->IsSet()) { |
| + while (true) { |
| PlatformThread::Sleep( |
| TimeDelta::FromMicroseconds(kSamplingFrequencyMicroseconds)); |
| GetSamples(); |
| + |
| + AutoLock lock(lock_); |
| + if (cancellation_flag_->IsSet()) |
| + break; |
|
Alexander Potapenko
2013/10/09 06:55:32
Nit: please fix the indentation
haraken
2013/10/09 07:05:07
Done.
|
| if (waitable_event_for_testing_.get()) |
| waitable_event_for_testing_->Signal(); |
| } |
| @@ -784,11 +790,13 @@ void TraceSamplingThread::ExtractCategoryAndName(const char* combined, |
| } |
| void TraceSamplingThread::Stop() { |
| + AutoLock lock(lock_); |
| cancellation_flag_->Set(); |
| } |
| void TraceSamplingThread::InstallWaitableEventForSamplingTesting( |
| WaitableEvent* waitable_event) { |
| + AutoLock lock(lock_); |
| waitable_event_for_testing_.reset(waitable_event); |
| } |