Index: base/debug/trace_event_impl.cc |
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc |
index 5276209add9e854f4c1adcce2150fb09fd8b9504..2be0332e183801e7f3eefc94ca026941b30beaf3 100644 |
--- a/base/debug/trace_event_impl.cc |
+++ b/base/debug/trace_event_impl.cc |
@@ -840,7 +840,7 @@ class TraceSamplingThread : public PlatformThread::Delegate { |
static void DefaultSamplingCallback(TraceBucketData* bucekt_data); |
void Stop(); |
- void InstallWaitableEventForSamplingTesting(WaitableEvent* waitable_event); |
+ void WaitSamplingEventForTesting(); |
private: |
friend class TraceLog; |
@@ -857,14 +857,14 @@ class TraceSamplingThread : public PlatformThread::Delegate { |
const char** name); |
std::vector<TraceBucketData> sample_buckets_; |
bool thread_running_; |
- scoped_ptr<CancellationFlag> cancellation_flag_; |
- scoped_ptr<WaitableEvent> waitable_event_for_testing_; |
+ CancellationFlag cancellation_flag_; |
+ WaitableEvent waitable_event_for_testing_; |
}; |
TraceSamplingThread::TraceSamplingThread() |
- : thread_running_(false) { |
- cancellation_flag_.reset(new CancellationFlag); |
+ : thread_running_(false), |
+ waitable_event_for_testing_(false, false) { |
} |
TraceSamplingThread::~TraceSamplingThread() { |
@@ -874,12 +874,11 @@ void TraceSamplingThread::ThreadMain() { |
PlatformThread::SetName("Sampling Thread"); |
thread_running_ = true; |
const int kSamplingFrequencyMicroseconds = 1000; |
- while (!cancellation_flag_->IsSet()) { |
+ while (!cancellation_flag_.IsSet()) { |
PlatformThread::Sleep( |
TimeDelta::FromMicroseconds(kSamplingFrequencyMicroseconds)); |
GetSamples(); |
- if (waitable_event_for_testing_.get()) |
- waitable_event_for_testing_->Signal(); |
+ waitable_event_for_testing_.Signal(); |
} |
} |
@@ -911,6 +910,9 @@ void TraceSamplingThread::RegisterSampleBucket( |
TRACE_EVENT_API_ATOMIC_WORD* bucket, |
const char* const name, |
TraceSampleCallback callback) { |
+ // Access to sample_buckets_ doesn't cause races with the sampling thread |
+ // that uses the sample_buckets_, because it is guaranteed that |
+ // RegisterSampleBucket is called before the sampling thread is created. |
DCHECK(!thread_running_); |
sample_buckets_.push_back(TraceBucketData(bucket, name, callback)); |
} |
@@ -924,12 +926,11 @@ void TraceSamplingThread::ExtractCategoryAndName(const char* combined, |
} |
void TraceSamplingThread::Stop() { |
- cancellation_flag_->Set(); |
+ cancellation_flag_.Set(); |
} |
-void TraceSamplingThread::InstallWaitableEventForSamplingTesting( |
- WaitableEvent* waitable_event) { |
- waitable_event_for_testing_.reset(waitable_event); |
+void TraceSamplingThread::WaitSamplingEventForTesting() { |
+ waitable_event_for_testing_.Wait(); |
} |
TraceBucketData::TraceBucketData(base::subtle::AtomicWord* bucket, |
@@ -2002,11 +2003,10 @@ void TraceLog::AddMetadataEventsWhileLocked() { |
} |
} |
-void TraceLog::InstallWaitableEventForSamplingTesting( |
- WaitableEvent* waitable_event) { |
+void TraceLog::WaitSamplingEventForTesting() { |
if (!sampling_thread_) |
return; |
- sampling_thread_->InstallWaitableEventForSamplingTesting(waitable_event); |
+ sampling_thread_->WaitSamplingEventForTesting(); |
} |
void TraceLog::DeleteForTesting() { |