Commit 5694ac22 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[cpu-profiler] Fix a TSAN false-positive by using std::atomic

TSAN was flakily detecting a race in the Add/RemoveSampler functions.
It could also be fixed by moving the USE(atomic_->Value()); line below
the do loop in the constructor of AtomicGuard.

Given that base::AtomicValue is deprecated and std::atomic has a
compare_exchange operation with std::memory_order_seq_cst, we can just
use std::atomic_bool to fix the TSAN false-positive.

Bug: v8:7702
Change-Id: Id2038ea1ccced7339f45991263e944394e935454
Reviewed-on: https://chromium-review.googlesource.com/c/1288814Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56794}
parent e5b4229b
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <pthread.h> #include <pthread.h>
#include <signal.h> #include <signal.h>
#include <sys/time.h> #include <sys/time.h>
#include <atomic>
#if !V8_OS_QNX && !V8_OS_AIX #if !V8_OS_QNX && !V8_OS_AIX
#include <sys/syscall.h> // NOLINT #include <sys/syscall.h> // NOLINT
...@@ -175,16 +176,15 @@ namespace { ...@@ -175,16 +176,15 @@ namespace {
#if defined(USE_SIGNALS) #if defined(USE_SIGNALS)
typedef std::vector<Sampler*> SamplerList; typedef std::vector<Sampler*> SamplerList;
typedef SamplerList::iterator SamplerListIterator; typedef SamplerList::iterator SamplerListIterator;
typedef base::AtomicValue<bool> AtomicMutex; typedef std::atomic_bool AtomicMutex;
class AtomicGuard { class AtomicGuard {
public: public:
explicit AtomicGuard(AtomicMutex* atomic, bool is_blocking = true) explicit AtomicGuard(AtomicMutex* atomic, bool is_blocking = true)
: atomic_(atomic), is_success_(false) { : atomic_(atomic), is_success_(false) {
do { do {
// Use Acquire_Load to gain mutual exclusion. bool expected = false;
USE(atomic_->Value()); is_success_ = atomic->compare_exchange_weak(expected, true);
is_success_ = atomic_->TrySetValue(false, true);
} while (is_blocking && !is_success_); } while (is_blocking && !is_success_);
} }
...@@ -192,7 +192,7 @@ class AtomicGuard { ...@@ -192,7 +192,7 @@ class AtomicGuard {
~AtomicGuard() { ~AtomicGuard() {
if (!is_success_) return; if (!is_success_) return;
atomic_->SetValue(false); atomic_->store(false);
} }
private: private:
......
...@@ -96,9 +96,6 @@ ...@@ -96,9 +96,6 @@
# BUG(v8:8209). Flaky # BUG(v8:8209). Flaky
'test-cpu-profiler/Issue1398': [SKIP], 'test-cpu-profiler/Issue1398': [SKIP],
# BUG(7702). Flaky data race and other test failures.
'test-cpu-profiler/MultipleProfilers': [SKIP],
# BUG(7202). The test is flaky. # BUG(7202). The test is flaky.
'test-cpu-profiler/NativeFrameStackTrace': [SKIP], 'test-cpu-profiler/NativeFrameStackTrace': [SKIP],
......
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