[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/1288814
Reviewed-by: Alexei Filippov <alph@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56794}
This commit is contained in:
Peter Marshall 2018-10-18 20:48:16 +02:00 committed by Commit Bot
parent e5b4229bd1
commit 5694ac2210
2 changed files with 5 additions and 8 deletions

View File

@ -12,6 +12,7 @@
#include <pthread.h>
#include <signal.h>
#include <sys/time.h>
#include <atomic>
#if !V8_OS_QNX && !V8_OS_AIX
#include <sys/syscall.h> // NOLINT
@ -175,16 +176,15 @@ namespace {
#if defined(USE_SIGNALS)
typedef std::vector<Sampler*> SamplerList;
typedef SamplerList::iterator SamplerListIterator;
typedef base::AtomicValue<bool> AtomicMutex;
typedef std::atomic_bool AtomicMutex;
class AtomicGuard {
public:
explicit AtomicGuard(AtomicMutex* atomic, bool is_blocking = true)
: atomic_(atomic), is_success_(false) {
do {
// Use Acquire_Load to gain mutual exclusion.
USE(atomic_->Value());
is_success_ = atomic_->TrySetValue(false, true);
bool expected = false;
is_success_ = atomic->compare_exchange_weak(expected, true);
} while (is_blocking && !is_success_);
}
@ -192,7 +192,7 @@ class AtomicGuard {
~AtomicGuard() {
if (!is_success_) return;
atomic_->SetValue(false);
atomic_->store(false);
}
private:

View File

@ -96,9 +96,6 @@
# BUG(v8:8209). Flaky
'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.
'test-cpu-profiler/NativeFrameStackTrace': [SKIP],