Commit 7271e97f authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[platform] Switch to std::atomic

We want to get rid of the atomicops library, hence switch all uses to
std::atomic.

R=mlippautz@chromium.org

Bug: v8:8926, v8:8834

Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_rel
Change-Id: I9b7cca83703775b1ddee4f16f51b7ad6535bb67c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1520717Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60233}
parent d82c9afb
......@@ -43,7 +43,7 @@
#include "src/base/utils/random-number-generator.h"
#ifdef V8_FAST_TLS_SUPPORTED
#include "src/base/atomicops.h"
#include <atomic>
#endif
#if V8_OS_MACOSX
......@@ -815,7 +815,7 @@ static pthread_key_t LocalKeyToPthreadKey(Thread::LocalStorageKey local_key) {
#ifdef V8_FAST_TLS_SUPPORTED
static Atomic32 tls_base_offset_initialized = 0;
static std::atomic<bool> tls_base_offset_initialized{false};
intptr_t kMacTlsBaseOffset = 0;
// It's safe to do the initialization more that once, but it has to be
......@@ -851,7 +851,7 @@ static void InitializeTlsBaseOffset() {
kMacTlsBaseOffset = 0;
}
Release_Store(&tls_base_offset_initialized, 1);
tls_base_offset_initialized.store(true, std::memory_order_release);
}
......@@ -871,7 +871,7 @@ static void CheckFastTls(Thread::LocalStorageKey key) {
Thread::LocalStorageKey Thread::CreateThreadLocalKey() {
#ifdef V8_FAST_TLS_SUPPORTED
bool check_fast_tls = false;
if (tls_base_offset_initialized == 0) {
if (!tls_base_offset_initialized.load(std::memory_order_acquire)) {
check_fast_tls = true;
InitializeTlsBaseOffset();
}
......
......@@ -19,7 +19,6 @@
#include <ostream>
#if V8_OS_WIN
#include "src/base/atomicops.h"
#include "src/base/lazy-instance.h"
#include "src/base/win32-headers.h"
#endif
......@@ -493,7 +492,7 @@ DWORD (*g_tick_function)(void) = &timeGetTimeWrapper;
// "rollover" counter.
union LastTimeAndRolloversState {
// The state as a single 32-bit opaque value.
base::Atomic32 as_opaque_32;
int32_t as_opaque_32;
// The state as usable values.
struct {
......@@ -509,7 +508,7 @@ union LastTimeAndRolloversState {
uint16_t rollovers;
} as_values;
};
base::Atomic32 g_last_time_and_rollovers = 0;
std::atomic<int32_t> g_last_time_and_rollovers{0};
static_assert(sizeof(LastTimeAndRolloversState) <=
sizeof(g_last_time_and_rollovers),
"LastTimeAndRolloversState does not fit in a single atomic word");
......@@ -523,12 +522,12 @@ TimeTicks RolloverProtectedNow() {
LastTimeAndRolloversState state;
DWORD now; // DWORD is always unsigned 32 bits.
while (true) {
// Fetch the "now" and "last" tick values, updating "last" with "now" and
// incrementing the "rollovers" counter if the tick-value has wrapped back
// around. Atomic operations ensure that both "last" and "rollovers" are
// always updated together.
int32_t original = base::Acquire_Load(&g_last_time_and_rollovers);
int32_t original = g_last_time_and_rollovers.load(std::memory_order_acquire);
while (true) {
state.as_opaque_32 = original;
now = g_tick_function();
uint8_t now_8 = static_cast<uint8_t>(now >> 24);
......@@ -540,11 +539,13 @@ TimeTicks RolloverProtectedNow() {
// Save the changed state. If the existing value is unchanged from the
// original, exit the loop.
int32_t check = base::Release_CompareAndSwap(&g_last_time_and_rollovers,
original, state.as_opaque_32);
if (check == original) break;
if (g_last_time_and_rollovers.compare_exchange_weak(
original, state.as_opaque_32, std::memory_order_acq_rel)) {
break;
}
// Another thread has done something in between so retry from the top.
// {original} has been updated by the {compare_exchange_weak}.
}
return TimeTicks() +
......
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