Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2830)

Unified Diff: base/debug/trace_event_impl.cc

Issue 28593003: Avoid threading races on TraceSamplingThread's members (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed races on WaitableEvent Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/debug/trace_event_impl.h ('k') | base/debug/trace_event_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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() {
« no previous file with comments | « base/debug/trace_event_impl.h ('k') | base/debug/trace_event_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698