Index: base/debug/trace_event_impl.cc |
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc |
index 4a365a773dc37a6d776eff5785ed1eb8d1ad989e..6a1ad65445ee786c6e19d053a3def3cef70e5203 100644 |
--- a/base/debug/trace_event_impl.cc |
+++ b/base/debug/trace_event_impl.cc |
@@ -714,6 +714,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_; |
@@ -722,6 +723,7 @@ class TraceSamplingThread : public PlatformThread::Delegate { |
TraceSamplingThread::TraceSamplingThread() |
: thread_running_(false) { |
+ AutoLock lock(lock_); |
cancellation_flag_.reset(new CancellationFlag); |
} |
@@ -732,10 +734,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; |
if (waitable_event_for_testing_.get()) |
waitable_event_for_testing_->Signal(); |
} |
@@ -782,11 +788,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); |
} |