5#ifndef RUNTIME_PLATFORM_ATOMIC_H_
6#define RUNTIME_PLATFORM_ATOMIC_H_
21 T load(std::memory_order order = std::memory_order_relaxed)
const {
22 return value_.load(order);
24 T load(std::memory_order order = std::memory_order_relaxed)
const volatile {
25 return value_.load(order);
27 void store(
T arg, std::memory_order order = std::memory_order_relaxed) {
28 value_.store(arg, order);
31 std::memory_order order = std::memory_order_relaxed)
volatile {
32 value_.store(arg, order);
35 T fetch_add(
T arg, std::memory_order order = std::memory_order_relaxed) {
36 return value_.fetch_add(arg, order);
38 T fetch_sub(
T arg, std::memory_order order = std::memory_order_relaxed) {
39 return value_.fetch_sub(arg, order);
41 T fetch_or(
T arg, std::memory_order order = std::memory_order_relaxed) {
42 return value_.fetch_or(arg, order);
44 T fetch_and(
T arg, std::memory_order order = std::memory_order_relaxed) {
45 return value_.fetch_and(arg, order);
48 T exchange(
T arg, std::memory_order order = std::memory_order_relaxed) {
49 return value_.exchange(arg, order);
55 std::memory_order order = std::memory_order_relaxed) {
56 return value_.compare_exchange_weak(expected, desired, order, order);
61 std::memory_order order = std::memory_order_relaxed)
volatile {
62 return value_.compare_exchange_weak(expected, desired, order, order);
67 std::memory_order order = std::memory_order_relaxed) {
68 return value_.compare_exchange_strong(expected, desired, order, order);
71 operator T()
const {
return load(); }
89 std::atomic<T> value_;
101 T load(std::memory_order order = std::memory_order_acquire)
const {
102 return value_.load(order);
104 void store(
T arg, std::memory_order order = std::memory_order_release) {
105 value_.store(arg, order);
108 T fetch_add(
T arg, std::memory_order order = std::memory_order_acq_rel) {
109 return value_.fetch_add(arg, order);
111 T fetch_sub(
T arg, std::memory_order order = std::memory_order_acq_rel) {
112 return value_.fetch_sub(arg, order);
114 T fetch_or(
T arg, std::memory_order order = std::memory_order_acq_rel) {
115 return value_.fetch_or(arg, order);
117 T fetch_and(
T arg, std::memory_order order = std::memory_order_acq_rel) {
118 return value_.fetch_and(arg, order);
124 std::memory_order success_order = std::memory_order_acq_rel,
125 std::memory_order failure_order = std::memory_order_acquire) {
126 return value_.compare_exchange_weak(expected, desired, success_order,
132 std::memory_order success_order = std::memory_order_acq_rel,
133 std::memory_order failure_order = std::memory_order_acquire) {
134 return value_.compare_exchange_strong(expected, desired, success_order,
139 operator T()
const =
delete;
146 std::atomic<T> value_;
151 static_assert(
sizeof(std::atomic<T>) ==
sizeof(
T));
152 return reinterpret_cast<const std::atomic<T>*
>(ptr)->
load(
153 std::memory_order_relaxed);
T fetch_or(T arg, std::memory_order order=std::memory_order_acq_rel)
AcqRelAtomic(const AcqRelAtomic &arg)=delete
T operator+=(T arg)=delete
T operator=(const AcqRelAtomic &arg)=delete
bool compare_exchange_weak(T &expected, T desired, std::memory_order success_order=std::memory_order_acq_rel, std::memory_order failure_order=std::memory_order_acquire)
T operator-=(T arg)=delete
T operator=(T arg)=delete
T load(std::memory_order order=std::memory_order_acquire) const
void store(T arg, std::memory_order order=std::memory_order_release)
bool compare_exchange_strong(T &expected, T desired, std::memory_order success_order=std::memory_order_acq_rel, std::memory_order failure_order=std::memory_order_acquire)
T fetch_and(T arg, std::memory_order order=std::memory_order_acq_rel)
T fetch_add(T arg, std::memory_order order=std::memory_order_acq_rel)
T fetch_sub(T arg, std::memory_order order=std::memory_order_acq_rel)
constexpr AcqRelAtomic(T arg)
void store(T arg, std::memory_order order=std::memory_order_relaxed) volatile
constexpr RelaxedAtomic()
T load(std::memory_order order=std::memory_order_relaxed) const
bool compare_exchange_weak(T &expected, T desired, std::memory_order order=std::memory_order_relaxed) volatile
bool compare_exchange_strong(T &expected, T desired, std::memory_order order=std::memory_order_relaxed)
T fetch_add(T arg, std::memory_order order=std::memory_order_relaxed)
RelaxedAtomic(const RelaxedAtomic &arg)
T fetch_and(T arg, std::memory_order order=std::memory_order_relaxed)
constexpr RelaxedAtomic(T arg)
T load(std::memory_order order=std::memory_order_relaxed) const volatile
bool compare_exchange_weak(T &expected, T desired, std::memory_order order=std::memory_order_relaxed)
void store(T arg, std::memory_order order=std::memory_order_relaxed)
T exchange(T arg, std::memory_order order=std::memory_order_relaxed)
T operator=(const RelaxedAtomic &arg)
T fetch_or(T arg, std::memory_order order=std::memory_order_relaxed)
T fetch_sub(T arg, std::memory_order order=std::memory_order_relaxed)
static T LoadRelaxed(const T *ptr)