X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/3e170ce000f1506b7b5d2c5c7faec85ceabb573d..527f99514973766e9c0382a4d8550dfb00f54939:/osfmk/i386/atomic.h diff --git a/osfmk/i386/atomic.h b/osfmk/i386/atomic.h index 2cbeae68b..ef4652d5c 100644 --- a/osfmk/i386/atomic.h +++ b/osfmk/i386/atomic.h @@ -49,5 +49,32 @@ #endif -#endif // _I386_ATOMIC_H_ +#ifdef ATOMIC_PRIVATE + +static boolean_t +atomic_compare_exchange(uintptr_t *target, uintptr_t oldval, uintptr_t newval, + enum memory_order ord, boolean_t wait) +{ + (void)wait; + return __c11_atomic_compare_exchange_strong((_Atomic uintptr_t *)target, &oldval, newval, ord, memory_order_relaxed); +} + +#endif // ATOMIC_PRIVATE +#define os_atomic_rmw_loop(p, ov, nv, m, ...) ({ \ + bool _result = false; \ + typeof(p) _p = (p); \ + ov = atomic_load_explicit(_p, memory_order_relaxed); \ + do { \ + __VA_ARGS__; \ + typeof(ov) _r = (ov); \ + _result = atomic_compare_exchange_weak_explicit(_p, &_r, nv, \ + memory_order_##m, memory_order_relaxed); \ + (ov) = _r; \ + } while (__builtin_expect(!_result, 0)); \ + _result; \ + }) + +#define os_atomic_rmw_loop_give_up(expr) ({ expr; __builtin_trap(); }) + +#endif // _I386_ATOMIC_H_