Commit 4d2da932 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[cpu-profiler][cleanup] Use std::atomic_bool for running flag

Mechanical change to use std:: atomics instead.

Change-Id: If64cc972eb247c93e7080e9eb764cbc6b2cf35ce
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2172966Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67487}
parent 542e85ad
...@@ -85,7 +85,6 @@ ProfilerEventsProcessor::ProfilerEventsProcessor( ...@@ -85,7 +85,6 @@ ProfilerEventsProcessor::ProfilerEventsProcessor(
: Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)),
generator_(generator), generator_(generator),
code_observer_(code_observer), code_observer_(code_observer),
running_(1),
last_code_event_id_(0), last_code_event_id_(0),
last_processed_code_event_id_(0), last_processed_code_event_id_(0),
isolate_(isolate) { isolate_(isolate) {
...@@ -150,7 +149,10 @@ void ProfilerEventsProcessor::AddSample(TickSample sample) { ...@@ -150,7 +149,10 @@ void ProfilerEventsProcessor::AddSample(TickSample sample) {
} }
void ProfilerEventsProcessor::StopSynchronously() { void ProfilerEventsProcessor::StopSynchronously() {
if (!base::Relaxed_AtomicExchange(&running_, 0)) return; bool expected = true;
if (!running_.compare_exchange_strong(expected, false,
std::memory_order_relaxed))
return;
{ {
base::MutexGuard guard(&running_mutex_); base::MutexGuard guard(&running_mutex_);
running_cond_.NotifyOne(); running_cond_.NotifyOne();
...@@ -225,7 +227,7 @@ SamplingEventsProcessor::ProcessOneSample() { ...@@ -225,7 +227,7 @@ SamplingEventsProcessor::ProcessOneSample() {
void SamplingEventsProcessor::Run() { void SamplingEventsProcessor::Run() {
base::MutexGuard guard(&running_mutex_); base::MutexGuard guard(&running_mutex_);
while (!!base::Relaxed_Load(&running_)) { while (running_.load(std::memory_order_relaxed)) {
base::TimeTicks nextSampleTime = base::TimeTicks nextSampleTime =
base::TimeTicks::HighResolutionNow() + period_; base::TimeTicks::HighResolutionNow() + period_;
base::TimeTicks now; base::TimeTicks now;
...@@ -262,7 +264,7 @@ void SamplingEventsProcessor::Run() { ...@@ -262,7 +264,7 @@ void SamplingEventsProcessor::Run() {
// If true was returned, we got interrupted before the timeout // If true was returned, we got interrupted before the timeout
// elapsed. If this was not due to a change in running state, a // elapsed. If this was not due to a change in running state, a
// spurious wakeup occurred (thus we should continue to wait). // spurious wakeup occurred (thus we should continue to wait).
if (!base::Relaxed_Load(&running_)) { if (!running_.load(std::memory_order_relaxed)) {
break; break;
} }
now = base::TimeTicks::HighResolutionNow(); now = base::TimeTicks::HighResolutionNow();
...@@ -288,7 +290,7 @@ void SamplingEventsProcessor::SetSamplingInterval(base::TimeDelta period) { ...@@ -288,7 +290,7 @@ void SamplingEventsProcessor::SetSamplingInterval(base::TimeDelta period) {
StopSynchronously(); StopSynchronously();
period_ = period; period_ = period;
base::Relaxed_Store(&running_, 1); running_.store(true, std::memory_order_relaxed);
StartSynchronously(); StartSynchronously();
} }
......
...@@ -5,10 +5,9 @@ ...@@ -5,10 +5,9 @@
#ifndef V8_PROFILER_CPU_PROFILER_H_ #ifndef V8_PROFILER_CPU_PROFILER_H_
#define V8_PROFILER_CPU_PROFILER_H_ #define V8_PROFILER_CPU_PROFILER_H_
#include <atomic>
#include <memory> #include <memory>
#include "src/base/atomic-utils.h"
#include "src/base/atomicops.h"
#include "src/base/platform/condition-variable.h" #include "src/base/platform/condition-variable.h"
#include "src/base/platform/mutex.h" #include "src/base/platform/mutex.h"
#include "src/base/platform/time.h" #include "src/base/platform/time.h"
...@@ -164,7 +163,7 @@ class V8_EXPORT_PRIVATE ProfilerEventsProcessor : public base::Thread, ...@@ -164,7 +163,7 @@ class V8_EXPORT_PRIVATE ProfilerEventsProcessor : public base::Thread,
// Thread control. // Thread control.
void Run() override = 0; void Run() override = 0;
void StopSynchronously(); void StopSynchronously();
V8_INLINE bool running() { return !!base::Relaxed_Load(&running_); } bool running() { return running_.load(std::memory_order_relaxed); }
void Enqueue(const CodeEventsContainer& event); void Enqueue(const CodeEventsContainer& event);
// Puts current stack into the tick sample events buffer. // Puts current stack into the tick sample events buffer.
...@@ -191,8 +190,7 @@ class V8_EXPORT_PRIVATE ProfilerEventsProcessor : public base::Thread, ...@@ -191,8 +190,7 @@ class V8_EXPORT_PRIVATE ProfilerEventsProcessor : public base::Thread,
ProfileGenerator* generator_; ProfileGenerator* generator_;
ProfilerCodeObserver* code_observer_; ProfilerCodeObserver* code_observer_;
// TODO(petermarshall): Use std::atomic and remove imports. std::atomic_bool running_{true};
base::Atomic32 running_;
base::ConditionVariable running_cond_; base::ConditionVariable running_cond_;
base::Mutex running_mutex_; base::Mutex running_mutex_;
LockedQueue<CodeEventsContainer> events_buffer_; LockedQueue<CodeEventsContainer> events_buffer_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment