#ifndef V8_BASE_ATOMICOPS_H_
#define V8_BASE_ATOMICOPS_H_
#include <stdint.h>
#include <atomic>
#include <cstddef>
#include "src/base/base-export.h"
#include "src/base/build_config.h"
#include "src/base/macros.h"
#if defined(V8_OS_STARBOARD)
#include "starboard/atomic.h"
#endif
namespace v8 {
namespace base {
#ifdef V8_OS_STARBOARD
using Atomic8 = SbAtomic8;
using Atomic16 = int16_t;
using Atomic32 = SbAtomic32;
#if SB_IS_64_BIT
using Atomic64 = SbAtomic64;
#endif
#else
Atomic8;
Atomic16;
Atomic32;
#if defined(V8_HOST_ARCH_64_BIT)
#if defined(__ILP32__)
using Atomic64 = int64_t;
#else
Atomic64;
#endif
#endif
#endif
#if defined(V8_HOST_ARCH_64_BIT)
AtomicWord;
#else
using AtomicWord = Atomic32;
#endif
static_assert …;
namespace helper {
template <typename T>
volatile std::atomic<T>* to_std_atomic(volatile T* ptr) { … }
template <typename T>
volatile const std::atomic<T>* to_std_atomic_const(volatile const T* ptr) { … }
}
inline void SeqCst_MemoryFence() { … }
inline Atomic8 Relaxed_CompareAndSwap(volatile Atomic8* ptr, Atomic8 old_value,
Atomic8 new_value) { … }
inline Atomic16 Relaxed_CompareAndSwap(volatile Atomic16* ptr,
Atomic16 old_value, Atomic16 new_value) { … }
inline Atomic32 Relaxed_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value, Atomic32 new_value) { … }
inline Atomic32 Relaxed_AtomicExchange(volatile Atomic32* ptr,
Atomic32 new_value) { … }
inline Atomic32 SeqCst_AtomicExchange(volatile Atomic32* ptr,
Atomic32 new_value) { … }
inline Atomic32 Relaxed_AtomicIncrement(volatile Atomic32* ptr,
Atomic32 increment) { … }
inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value, Atomic32 new_value) { … }
inline Atomic8 Release_CompareAndSwap(volatile Atomic8* ptr, Atomic8 old_value,
Atomic8 new_value) { … }
inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value, Atomic32 new_value) { … }
inline Atomic32 AcquireRelease_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) { … }
inline Atomic32 SeqCst_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value, Atomic32 new_value) { … }
inline void Relaxed_Store(volatile Atomic8* ptr, Atomic8 value) { … }
inline void Relaxed_Store(volatile Atomic16* ptr, Atomic16 value) { … }
inline void Relaxed_Store(volatile Atomic32* ptr, Atomic32 value) { … }
inline void Release_Store(volatile Atomic8* ptr, Atomic8 value) { … }
inline void Release_Store(volatile Atomic16* ptr, Atomic16 value) { … }
inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { … }
inline void SeqCst_Store(volatile Atomic8* ptr, Atomic8 value) { … }
inline void SeqCst_Store(volatile Atomic16* ptr, Atomic16 value) { … }
inline void SeqCst_Store(volatile Atomic32* ptr, Atomic32 value) { … }
inline Atomic8 Relaxed_Load(volatile const Atomic8* ptr) { … }
inline Atomic16 Relaxed_Load(volatile const Atomic16* ptr) { … }
inline Atomic32 Relaxed_Load(volatile const Atomic32* ptr) { … }
inline Atomic8 Acquire_Load(volatile const Atomic8* ptr) { … }
inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { … }
inline Atomic8 SeqCst_Load(volatile const Atomic8* ptr) { … }
inline Atomic32 SeqCst_Load(volatile const Atomic32* ptr) { … }
#if defined(V8_HOST_ARCH_64_BIT)
inline Atomic64 Relaxed_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value, Atomic64 new_value) { … }
inline Atomic64 Relaxed_AtomicExchange(volatile Atomic64* ptr,
Atomic64 new_value) { … }
inline Atomic64 SeqCst_AtomicExchange(volatile Atomic64* ptr,
Atomic64 new_value) { … }
inline Atomic64 Relaxed_AtomicIncrement(volatile Atomic64* ptr,
Atomic64 increment) { … }
inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value, Atomic64 new_value) { … }
inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value, Atomic64 new_value) { … }
inline Atomic64 AcquireRelease_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) { … }
inline Atomic64 SeqCst_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value, Atomic64 new_value) { … }
inline void Relaxed_Store(volatile Atomic64* ptr, Atomic64 value) { … }
inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { … }
inline void SeqCst_Store(volatile Atomic64* ptr, Atomic64 value) { … }
inline Atomic64 Relaxed_Load(volatile const Atomic64* ptr) { … }
inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { … }
inline Atomic64 SeqCst_Load(volatile const Atomic64* ptr) { … }
#endif
inline void Relaxed_Memcpy(volatile Atomic8* dst, volatile const Atomic8* src,
size_t bytes) { … }
inline void Relaxed_Memmove(volatile Atomic8* dst, volatile const Atomic8* src,
size_t bytes) { … }
namespace helper {
inline int MemcmpNotEqualFundamental(Atomic8 u1, Atomic8 u2) { … }
inline int MemcmpNotEqualFundamental(AtomicWord u1, AtomicWord u2) { … }
}
inline int Relaxed_Memcmp(volatile const Atomic8* s1,
volatile const Atomic8* s2, size_t len) { … }
}
}
#endif