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

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: Addressed comments 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 | tools/valgrind/tsan_v2/suppressions.txt » ('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 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);
}
« no previous file with comments | « no previous file | tools/valgrind/tsan_v2/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698