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

Unified Diff: base/debug/trace_event_impl.cc

Issue 26541005: Avoid threading races on TraceSamplingThread's members. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | « no previous file | no next file » | 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 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);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698