[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/+/2172966 Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Commit-Queue: Peter Marshall <petermarshall@chromium.org> Cr-Commit-Position: refs/heads/master@{#67487}
This commit is contained in:
parent
542e85ad25
commit
4d2da93235
@ -85,7 +85,6 @@ ProfilerEventsProcessor::ProfilerEventsProcessor(
|
||||
: Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)),
|
||||
generator_(generator),
|
||||
code_observer_(code_observer),
|
||||
running_(1),
|
||||
last_code_event_id_(0),
|
||||
last_processed_code_event_id_(0),
|
||||
isolate_(isolate) {
|
||||
@ -150,7 +149,10 @@ void ProfilerEventsProcessor::AddSample(TickSample sample) {
|
||||
}
|
||||
|
||||
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_);
|
||||
running_cond_.NotifyOne();
|
||||
@ -225,7 +227,7 @@ SamplingEventsProcessor::ProcessOneSample() {
|
||||
|
||||
void SamplingEventsProcessor::Run() {
|
||||
base::MutexGuard guard(&running_mutex_);
|
||||
while (!!base::Relaxed_Load(&running_)) {
|
||||
while (running_.load(std::memory_order_relaxed)) {
|
||||
base::TimeTicks nextSampleTime =
|
||||
base::TimeTicks::HighResolutionNow() + period_;
|
||||
base::TimeTicks now;
|
||||
@ -262,7 +264,7 @@ void SamplingEventsProcessor::Run() {
|
||||
// If true was returned, we got interrupted before the timeout
|
||||
// elapsed. If this was not due to a change in running state, a
|
||||
// spurious wakeup occurred (thus we should continue to wait).
|
||||
if (!base::Relaxed_Load(&running_)) {
|
||||
if (!running_.load(std::memory_order_relaxed)) {
|
||||
break;
|
||||
}
|
||||
now = base::TimeTicks::HighResolutionNow();
|
||||
@ -288,7 +290,7 @@ void SamplingEventsProcessor::SetSamplingInterval(base::TimeDelta period) {
|
||||
StopSynchronously();
|
||||
|
||||
period_ = period;
|
||||
base::Relaxed_Store(&running_, 1);
|
||||
running_.store(true, std::memory_order_relaxed);
|
||||
|
||||
StartSynchronously();
|
||||
}
|
||||
|
@ -5,10 +5,9 @@
|
||||
#ifndef V8_PROFILER_CPU_PROFILER_H_
|
||||
#define V8_PROFILER_CPU_PROFILER_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include "src/base/atomic-utils.h"
|
||||
#include "src/base/atomicops.h"
|
||||
#include "src/base/platform/condition-variable.h"
|
||||
#include "src/base/platform/mutex.h"
|
||||
#include "src/base/platform/time.h"
|
||||
@ -164,7 +163,7 @@ class V8_EXPORT_PRIVATE ProfilerEventsProcessor : public base::Thread,
|
||||
// Thread control.
|
||||
void Run() override = 0;
|
||||
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);
|
||||
|
||||
// Puts current stack into the tick sample events buffer.
|
||||
@ -191,8 +190,7 @@ class V8_EXPORT_PRIVATE ProfilerEventsProcessor : public base::Thread,
|
||||
|
||||
ProfileGenerator* generator_;
|
||||
ProfilerCodeObserver* code_observer_;
|
||||
// TODO(petermarshall): Use std::atomic and remove imports.
|
||||
base::Atomic32 running_;
|
||||
std::atomic_bool running_{true};
|
||||
base::ConditionVariable running_cond_;
|
||||
base::Mutex running_mutex_;
|
||||
LockedQueue<CodeEventsContainer> events_buffer_;
|
||||
|
Loading…
Reference in New Issue
Block a user