]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/atomic.h
xnu-4570.41.2.tar.gz
[apple/xnu.git] / osfmk / i386 / atomic.h
index 2cbeae68b6a05ee257f4cd11a43748e418c4c8e6..ef4652d5cd5244da0f64c4f3bd7fef09df678298 100644 (file)
 
 #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_