From: jochen@chromium.org Date: Tue, 7 Oct 2014 14:45:17 +0000 (+0000) Subject: Fix data race on CpuProfiler::running_ X-Git-Tag: upstream/4.7.83~6513 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7f61f657ce06d60733646b1da06ef45d4ce1f337;p=platform%2Fupstream%2Fv8.git Fix data race on CpuProfiler::running_ BUG=v8:3613 R=yangguo@chromium.org LOG=n Review URL: https://codereview.chromium.org/632313002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24439 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/cpu-profiler.cc b/src/cpu-profiler.cc index 68a565c..8bd3e4d 100644 --- a/src/cpu-profiler.cc +++ b/src/cpu-profiler.cc @@ -20,17 +20,16 @@ namespace internal { static const int kProfilerStackSize = 64 * KB; -ProfilerEventsProcessor::ProfilerEventsProcessor( - ProfileGenerator* generator, - Sampler* sampler, - base::TimeDelta period) +ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator, + Sampler* sampler, + base::TimeDelta period) : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), generator_(generator), sampler_(sampler), - running_(true), + running_(1), period_(period), - last_code_event_id_(0), last_processed_code_event_id_(0) { -} + last_code_event_id_(0), + last_processed_code_event_id_(0) {} void ProfilerEventsProcessor::Enqueue(const CodeEventsContainer& event) { @@ -55,8 +54,7 @@ void ProfilerEventsProcessor::AddCurrentStack(Isolate* isolate) { void ProfilerEventsProcessor::StopSynchronously() { - if (!running_) return; - running_ = false; + if (!base::NoBarrier_AtomicExchange(&running_, 0)) return; Join(); } @@ -107,7 +105,7 @@ ProfilerEventsProcessor::SampleProcessingResult void ProfilerEventsProcessor::Run() { - while (running_) { + while (!!base::NoBarrier_Load(&running_)) { base::ElapsedTimer timer; timer.Start(); // Keep processing existing events until we need to do next sample. diff --git a/src/cpu-profiler.h b/src/cpu-profiler.h index c1e75a1..4dc5643 100644 --- a/src/cpu-profiler.h +++ b/src/cpu-profiler.h @@ -132,7 +132,7 @@ class ProfilerEventsProcessor : public base::Thread { // Thread control. virtual void Run(); void StopSynchronously(); - INLINE(bool running()) { return running_; } + INLINE(bool running()) { return !!base::NoBarrier_Load(&running_); } void Enqueue(const CodeEventsContainer& event); // Puts current stack into tick sample events buffer. @@ -163,7 +163,7 @@ class ProfilerEventsProcessor : public base::Thread { ProfileGenerator* generator_; Sampler* sampler_; - bool running_; + base::Atomic32 running_; // Sampling period in microseconds. const base::TimeDelta period_; UnboundQueue events_buffer_;