Commit 435af6a5 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[base] Add atomic CAS operation for 16-bit integers.

The operation will be used for marking of descriptor arrays.

Bug: v8:8486
Change-Id: If73be030614e2c84c77eaeeff419c08ef34a76e9
Reviewed-on: https://chromium-review.googlesource.com/c/1382456Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58322}
parent 11abc5ec
......@@ -66,6 +66,8 @@ typedef intptr_t AtomicWord;
// Always return the old value of "*ptr"
//
// This routine implies no memory barriers.
Atomic16 Relaxed_CompareAndSwap(volatile Atomic16* ptr, Atomic16 old_value,
Atomic16 new_value);
Atomic32 Relaxed_CompareAndSwap(volatile Atomic32* ptr, Atomic32 old_value,
Atomic32 new_value);
......
......@@ -50,6 +50,13 @@ inline void SeqCst_MemoryFence() {
#endif
}
inline Atomic16 Relaxed_CompareAndSwap(volatile Atomic16* ptr,
Atomic16 old_value, Atomic16 new_value) {
__atomic_compare_exchange_n(ptr, &old_value, new_value, false,
__ATOMIC_RELAXED, __ATOMIC_RELAXED);
return old_value;
}
inline Atomic32 Relaxed_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value, Atomic32 new_value) {
__atomic_compare_exchange_n(ptr, &old_value, new_value, false,
......
......@@ -28,6 +28,14 @@ inline void SeqCst_MemoryFence() {
std::atomic_thread_fence(std::memory_order_seq_cst);
}
inline Atomic16 Relaxed_CompareAndSwap(volatile Atomic16* ptr,
Atomic16 old_value, Atomic16 new_value) {
std::atomic_compare_exchange_strong_explicit(
helper::to_std_atomic(ptr), &old_value, new_value,
std::memory_order_relaxed, std::memory_order_relaxed);
return old_value;
}
inline Atomic32 Relaxed_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value, Atomic32 new_value) {
std::atomic_compare_exchange_strong_explicit(
......
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