123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532 |
- #include <intrin.h>
- static inline void atomic_thread_fence(memory_order_relaxed_t)
- {
- }
- static inline void atomic_thread_fence(memory_order_acquire_t)
- {
- __dmb(_ARM64_BARRIER_ISH);
- }
- static inline void atomic_thread_fence(memory_order_release_t)
- {
- __dmb(_ARM64_BARRIER_ISH);
- }
- static inline void atomic_thread_fence(memory_order_acq_rel_t)
- {
- __dmb(_ARM64_BARRIER_ISH);
- }
- static inline void atomic_thread_fence(int /* memory_order_seq_cst_t */)
- {
- __dmb(_ARM64_BARRIER_ISH);
- }
- static inline int atomic_load_explicit(const volatile int* p, memory_order_relaxed_t)
- {
- return __iso_volatile_load32(p);
- }
- static inline int atomic_load_explicit(const volatile int* p, memory_order_acquire_t)
- {
- int res = __iso_volatile_load32(p);
- __dmb(_ARM64_BARRIER_ISH);
- return res;
- }
- static inline int atomic_load_explicit(const volatile int* p, int /* memory_order_seq_cst_t */)
- {
- int res = __iso_volatile_load32(p);
- __dmb(_ARM64_BARRIER_ISH);
- return res;
- }
- static inline atomic_word atomic_load_explicit(const volatile atomic_word* p, memory_order_relaxed_t)
- {
- return __iso_volatile_load64(p);
- }
- static inline atomic_word atomic_load_explicit(const volatile atomic_word* p, memory_order_acquire_t)
- {
- atomic_word res = __iso_volatile_load64(p);
- __dmb(_ARM64_BARRIER_ISH);
- return res;
- }
- static inline atomic_word atomic_load_explicit(const volatile atomic_word* p, int /* memory_order_seq_cst_t */)
- {
- atomic_word res = __iso_volatile_load64(p);
- __dmb(_ARM64_BARRIER_ISH);
- return res;
- }
- static inline void atomic_store_explicit(volatile int* p, int v, memory_order_relaxed_t)
- {
- __iso_volatile_store32(p, v);
- }
- static inline void atomic_store_explicit(volatile int* p, int v, memory_order_release_t)
- {
- __dmb(_ARM64_BARRIER_ISH);
- __iso_volatile_store32(p, v);
- }
- static inline void atomic_store_explicit(volatile int* p, int v, int /* memory_order_seq_cst_t */)
- {
- __dmb(_ARM64_BARRIER_ISH);
- __iso_volatile_store32(p, v);
- __dmb(_ARM64_BARRIER_ISH);
- }
- static inline void atomic_store_explicit(volatile atomic_word* p, atomic_word v, memory_order_relaxed_t)
- {
- __iso_volatile_store64(p, v);
- }
- static inline void atomic_store_explicit(volatile atomic_word* p, atomic_word v, memory_order_release_t)
- {
- __dmb(_ARM64_BARRIER_ISH);
- __iso_volatile_store64(p, v);
- }
- static inline void atomic_store_explicit(volatile atomic_word* p, atomic_word v, int /* memory_order_seq_cst_t */)
- {
- __dmb(_ARM64_BARRIER_ISH);
- __iso_volatile_store64(p, v);
- __dmb(_ARM64_BARRIER_ISH);
- }
- static inline int atomic_exchange_explicit(volatile int* p, int v, memory_order_relaxed_t)
- {
- return _InterlockedExchange_nf(reinterpret_cast<volatile long*>(p), v);
- }
- static inline int atomic_exchange_explicit(volatile int* p, int v, memory_order_acquire_t)
- {
- return _InterlockedExchange_acq(reinterpret_cast<volatile long*>(p), v);
- }
- static inline int atomic_exchange_explicit(volatile int* p, int v, memory_order_release_t)
- {
- return _InterlockedExchange_rel(reinterpret_cast<volatile long*>(p), v);
- }
- static inline int atomic_exchange_explicit(volatile int* p, int v, memory_order_acq_rel_t)
- {
- return _InterlockedExchange(reinterpret_cast<volatile long*>(p), v);
- }
- static inline int atomic_exchange_explicit(volatile int* p, int v, int /* memory_order_seq_cst_t */)
- {
- return _InterlockedExchange(reinterpret_cast<volatile long*>(p), v);
- }
- static inline atomic_word atomic_exchange_explicit(volatile atomic_word* p, atomic_word v, memory_order_relaxed_t)
- {
- return _InterlockedExchange64_nf(p, v);
- }
- static inline atomic_word atomic_exchange_explicit(volatile atomic_word* p, atomic_word v, memory_order_acquire_t)
- {
- return _InterlockedExchange64_acq(p, v);
- }
- static inline atomic_word atomic_exchange_explicit(volatile atomic_word* p, atomic_word v, memory_order_release_t)
- {
- return _InterlockedExchange64_rel(p, v);
- }
- static inline atomic_word atomic_exchange_explicit(volatile atomic_word* p, atomic_word v, memory_order_acq_rel_t)
- {
- return _InterlockedExchange64(p, v);
- }
- static inline atomic_word atomic_exchange_explicit(volatile atomic_word* p, atomic_word v, int /* memory_order_seq_cst_t */)
- {
- return _InterlockedExchange64(p, v);
- }
- // atomic_compare_exchange_weak_explicit: can fail spuriously even if *p == *oldval
- #undef ATOMIC_CMP_XCHG
- #define ATOMIC_CMP_XCHG(valueType, p, oldval, newval, exchangeFunction) \
- do \
- { \
- valueType oldValue = *oldval; \
- valueType previousValue = exchangeFunction(p, newval, oldValue); \
- if (previousValue == oldValue) \
- return true; \
- \
- *oldval = previousValue; \
- return false; \
- } \
- while (false)
- static inline bool atomic_compare_exchange_weak_explicit(volatile int* p, int *oldval, int newval, memory_order_relaxed_t, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange_nf);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile int* p, int *oldval, int newval, memory_order_acquire_t, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange_acq);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile int* p, int *oldval, int newval, memory_order_release_t, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange_rel);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile int* p, int *oldval, int newval, memory_order_acq_rel_t, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile int* p, int *oldval, int newval, int /* memory_order_seq_cst_t */, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile int* p, int *oldval, int newval, memory_order_acquire_t, memory_order_acquire_t)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange_acq);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile int* p, int *oldval, int newval, memory_order_release_t, memory_order_release_t)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange_rel);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile int* p, int *oldval, int newval, memory_order_acq_rel_t, memory_order_acq_rel_t)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile int* p, int *oldval, int newval, int /* memory_order_seq_cst_t */, int /* memory_order_seq_cst_t */)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, memory_order_relaxed_t, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64_nf);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, memory_order_acquire_t, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64_acq);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, memory_order_release_t, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64_rel);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, memory_order_acq_rel_t, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, int /* memory_order_seq_cst_t */, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, memory_order_acquire_t, memory_order_acquire_t)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64_acq);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, memory_order_release_t, memory_order_release_t)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64_rel);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, memory_order_acq_rel_t, memory_order_acq_rel_t)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64);
- }
- static inline bool atomic_compare_exchange_weak_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, int /* memory_order_seq_cst_t */, int /* memory_order_seq_cst_t */)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64);
- }
- // atomic_compare_exchange_strong_explicit: does loop and only returns false if *p != *oldval
- static inline bool atomic_compare_exchange_strong_explicit(volatile int* p, int *oldval, int newval, memory_order_relaxed_t, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange_nf);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile int* p, int *oldval, int newval, memory_order_acquire_t, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange_acq);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile int* p, int *oldval, int newval, memory_order_release_t, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange_rel);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile int* p, int *oldval, int newval, memory_order_acq_rel_t, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile int* p, int *oldval, int newval, int /* memory_order_seq_cst_t */, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile int* p, int *oldval, int newval, memory_order_acquire_t, memory_order_acquire_t)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange_acq);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile int* p, int *oldval, int newval, memory_order_release_t, memory_order_release_t)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange_rel);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile int* p, int *oldval, int newval, memory_order_acq_rel_t, memory_order_acq_rel_t)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile int* p, int *oldval, int newval, int /* memory_order_seq_cst_t */, int /* memory_order_seq_cst_t */)
- {
- ATOMIC_CMP_XCHG(long, reinterpret_cast<volatile long*>(p), oldval, newval, _InterlockedCompareExchange);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, memory_order_relaxed_t, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64_nf);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, memory_order_acquire_t, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64_acq);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, memory_order_release_t, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64_rel);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, memory_order_acq_rel_t, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, int /* memory_order_seq_cst_t */, memory_order_relaxed_t)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, memory_order_acquire_t, memory_order_acquire_t)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64_acq);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, memory_order_release_t, memory_order_release_t)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64_rel);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, memory_order_acq_rel_t, memory_order_acq_rel_t)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile atomic_word* p, atomic_word *oldval, atomic_word newval, int /* memory_order_seq_cst_t */, int /* memory_order_seq_cst_t */)
- {
- ATOMIC_CMP_XCHG(atomic_word, p, oldval, newval, _InterlockedCompareExchange64);
- }
- static inline int atomic_fetch_add_explicit(volatile int* p, int v, memory_order_relaxed_t)
- {
- return _InterlockedExchangeAdd_nf(reinterpret_cast<volatile long*>(p), v);
- }
- static inline int atomic_fetch_add_explicit(volatile int* p, int v, memory_order_acquire_t)
- {
- return _InterlockedExchangeAdd_acq(reinterpret_cast<volatile long*>(p), v);
- }
- static inline int atomic_fetch_add_explicit(volatile int* p, int v, memory_order_release_t)
- {
- return _InterlockedExchangeAdd_rel(reinterpret_cast<volatile long*>(p), v);
- }
- static inline int atomic_fetch_add_explicit(volatile int* p, int v, memory_order_acq_rel_t)
- {
- return _InterlockedExchangeAdd(reinterpret_cast<volatile long*>(p), v);
- }
- static inline int atomic_fetch_add_explicit(volatile int* p, int v, int /* memory_order_seq_cst_t */)
- {
- return _InterlockedExchangeAdd(reinterpret_cast<volatile long*>(p), v);
- }
- static inline atomic_word atomic_fetch_add_explicit(volatile atomic_word* p, atomic_word v, memory_order_relaxed_t)
- {
- return _InterlockedExchangeAdd64_nf(p, v);
- }
- static inline atomic_word atomic_fetch_add_explicit(volatile atomic_word* p, atomic_word v, memory_order_acquire_t)
- {
- return _InterlockedExchangeAdd64_acq(p, v);
- }
- static inline atomic_word atomic_fetch_add_explicit(volatile atomic_word* p, atomic_word v, memory_order_release_t)
- {
- return _InterlockedExchangeAdd64_rel(p, v);
- }
- static inline atomic_word atomic_fetch_add_explicit(volatile atomic_word* p, atomic_word v, memory_order_acq_rel_t)
- {
- return _InterlockedExchangeAdd64(p, v);
- }
- static inline atomic_word atomic_fetch_add_explicit(volatile atomic_word* p, atomic_word v, int /* memory_order_seq_cst_t */)
- {
- return _InterlockedExchangeAdd64(p, v);
- }
- static inline int atomic_fetch_sub_explicit(volatile int* p, int v, memory_order_relaxed_t)
- {
- return _InterlockedExchangeAdd_nf(reinterpret_cast<volatile long*>(p), -v);
- }
- static inline int atomic_fetch_sub_explicit(volatile int* p, int v, memory_order_acquire_t)
- {
- return _InterlockedExchangeAdd_acq(reinterpret_cast<volatile long*>(p), -v);
- }
- static inline int atomic_fetch_sub_explicit(volatile int* p, int v, memory_order_release_t)
- {
- return _InterlockedExchangeAdd_rel(reinterpret_cast<volatile long*>(p), -v);
- }
- static inline int atomic_fetch_sub_explicit(volatile int* p, int v, memory_order_acq_rel_t)
- {
- return _InterlockedExchangeAdd(reinterpret_cast<volatile long*>(p), -v);
- }
- static inline int atomic_fetch_sub_explicit(volatile int* p, int v, int /* memory_order_seq_cst_t */)
- {
- return _InterlockedExchangeAdd(reinterpret_cast<volatile long*>(p), -v);
- }
- static inline atomic_word atomic_fetch_sub_explicit(volatile atomic_word* p, atomic_word v, memory_order_relaxed_t)
- {
- return _InterlockedExchangeAdd64_nf(p, -v);
- }
- static inline atomic_word atomic_fetch_sub_explicit(volatile atomic_word* p, atomic_word v, memory_order_acquire_t)
- {
- return _InterlockedExchangeAdd64_acq(p, -v);
- }
- static inline atomic_word atomic_fetch_sub_explicit(volatile atomic_word* p, atomic_word v, memory_order_release_t)
- {
- return _InterlockedExchangeAdd64_rel(p, -v);
- }
- static inline atomic_word atomic_fetch_sub_explicit(volatile atomic_word* p, atomic_word v, memory_order_acq_rel_t)
- {
- return _InterlockedExchangeAdd64(p, -v);
- }
- static inline atomic_word atomic_fetch_sub_explicit(volatile atomic_word* p, atomic_word v, int /* memory_order_seq_cst_t */)
- {
- return _InterlockedExchangeAdd64(p, -v);
- }
- /*
- * extensions
- */
- static inline void atomic_retain(volatile int* p)
- {
- atomic_fetch_add_explicit(p, 1, memory_order_relaxed);
- }
- static inline bool atomic_release(volatile int* p)
- {
- bool res = atomic_fetch_sub_explicit(p, 1, memory_order_release) == 1;
- if (res)
- {
- atomic_thread_fence(memory_order_acquire);
- }
- return res;
- }
- /*
- * double word
- */
- static inline atomic_word2 atomic_load_explicit(const volatile atomic_word2* p, memory_order_relaxed_t)
- {
- atomic_word2 result = { 0, 0 };
- _InterlockedCompareExchange128_nf(/* _Destination */ const_cast<volatile atomic_word*>(&p->lo), /* _ExchangeHigh */ 0, /* _ExchangeLow */ 0, /* _ComparandResult */ &result.lo);
- return result;
- }
- static inline atomic_word2 atomic_load_explicit(const volatile atomic_word2* p, memory_order_acquire_t)
- {
- atomic_word2 result = { 0, 0 };
- _InterlockedCompareExchange128_acq(/* _Destination */ const_cast<volatile atomic_word*>(&p->lo), /* _ExchangeHigh */ 0, /* _ExchangeLow */ 0, /* _ComparandResult */ &result.lo);
- return result;
- }
- static inline void atomic_store_explicit(volatile atomic_word2* p, atomic_word2 v, memory_order_relaxed_t)
- {
- atomic_word2 comparand = v;
- while (!_InterlockedCompareExchange128_nf(/* _Destination */ &p->lo, /* _ExchangeHigh */ v.hi, /* _ExchangeLow */ v.lo, /* _ComparandResult */ &comparand.lo))
- {
- }
- }
- static inline void atomic_store_explicit(volatile atomic_word2* p, atomic_word2 v, memory_order_release_t)
- {
- atomic_word2 comparand = v;
- while (!_InterlockedCompareExchange128_rel(/* _Destination */ &p->lo, /* _ExchangeHigh */ v.hi, /* _ExchangeLow */ v.lo, /* _ComparandResult */ &comparand.lo))
- {
- }
- }
- static inline atomic_word2 atomic_exchange_explicit(volatile atomic_word2* p, atomic_word2 val, memory_order_acq_rel_t)
- {
- atomic_word2 comparand = val;
- while (!_InterlockedCompareExchange128(/* _Destination */ &p->lo, /* _ExchangeHigh */ val.hi, /* _ExchangeLow */ val.lo, /* _ComparandResult */ &comparand.lo))
- {
- }
- return comparand;
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile atomic_word2* p, atomic_word2* oldval, atomic_word2 newval, memory_order_acquire_t, memory_order_relaxed_t)
- {
- return _InterlockedCompareExchange128_acq(/* _Destination */ &p->lo, /* _ExchangeHigh */ newval.hi, /* _ExchangeLow */ newval.lo, /* _ComparandResult */ &oldval->lo);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile atomic_word2* p, atomic_word2* oldval, atomic_word2 newval, memory_order_release_t, memory_order_relaxed_t)
- {
- return _InterlockedCompareExchange128_rel(/* _Destination */ &p->lo, /* _ExchangeHigh */ newval.hi, /* _ExchangeLow */ newval.lo, /* _ComparandResult */ &oldval->lo);
- }
- static inline bool atomic_compare_exchange_strong_explicit(volatile atomic_word2* p, atomic_word2* oldval, atomic_word2 newval, int /*memory_order_acq_rel_t*/, memory_order_relaxed_t)
- {
- return _InterlockedCompareExchange128(/* _Destination */ &p->lo, /* _ExchangeHigh */ newval.hi, /* _ExchangeLow */ newval.lo, /* _ComparandResult */ &oldval->lo);
- }
- template<class SuccOrder, class FailOrder>
- static inline bool atomic_compare_exchange_weak_explicit(volatile atomic_word2* p, atomic_word2* oldval, atomic_word2 newval, SuccOrder o1, FailOrder o2)
- {
- // TODO: implement proper weak compare exchange
- return atomic_compare_exchange_strong_explicit(p, oldval, newval, o1, o2);
- }
|