]> 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 22ca1fd5077ad49ac2f690f1955fb184eaf590aa..ef4652d5cd5244da0f64c4f3bd7fef09df678298 100644 (file)
@@ -61,6 +61,20 @@ atomic_compare_exchange(uintptr_t *target, uintptr_t oldval, uintptr_t newval,
 
 #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; \
+       })
 
-#endif // _I386_ATOMIC_H_
+#define os_atomic_rmw_loop_give_up(expr) ({ expr; __builtin_trap(); })
 
+#endif // _I386_ATOMIC_H_