]> granicus.if.org Git - libatomic_ops/commitdiff
Add missing generalization of no-barrier CAS in template
authorIvan Maidanski <ivmai@mail.ru>
Wed, 2 Jan 2013 09:40:21 +0000 (13:40 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 2 Jan 2013 09:40:21 +0000 (13:40 +0400)
* src/atomic_ops/generalize-small.template
(AO_XSIZE_compare_and_swap): Add missed definition (based on
AO_XSIZE_fetch_compare_and_swap).
* src/atomic_ops/generalize-small.template
(AO_XSIZE_fetch_and_add_full): Add comment (copy from generalize.h).
* src/atomic_ops/generalize-small.h: Regenerate.

src/atomic_ops/generalize-small.h
src/atomic_ops/generalize-small.template

index 44d16ff5f556fb19647fafcdefa8af7cff4f6319..3dfc18b05687a6802024baddc2f3394e8a749f63 100644 (file)
 # define AO_HAVE_char_compare_and_swap_release
 #endif
 
+#if defined(AO_HAVE_char_fetch_compare_and_swap) \
+    && !defined(AO_HAVE_char_compare_and_swap)
+  AO_INLINE int
+  AO_char_compare_and_swap(volatile unsigned/**/char *addr, unsigned/**/char old_val,
+                            unsigned/**/char new_val)
+  {
+    return AO_char_fetch_compare_and_swap(addr, old_val, new_val) == old_val;
+  }
+# define AO_HAVE_char_compare_and_swap
+#endif
+
 /* char_fetch_and_add */
+/* We first try to implement fetch_and_add variants in terms of the     */
+/* corresponding compare_and_swap variants to minimize adding barriers. */
 #if defined(AO_HAVE_char_compare_and_swap_full) \
     && !defined(AO_HAVE_char_fetch_and_add_full)
   AO_INLINE unsigned/**/char
 # define AO_HAVE_short_compare_and_swap_release
 #endif
 
+#if defined(AO_HAVE_short_fetch_compare_and_swap) \
+    && !defined(AO_HAVE_short_compare_and_swap)
+  AO_INLINE int
+  AO_short_compare_and_swap(volatile unsigned/**/short *addr, unsigned/**/short old_val,
+                            unsigned/**/short new_val)
+  {
+    return AO_short_fetch_compare_and_swap(addr, old_val, new_val) == old_val;
+  }
+# define AO_HAVE_short_compare_and_swap
+#endif
+
 /* short_fetch_and_add */
+/* We first try to implement fetch_and_add variants in terms of the     */
+/* corresponding compare_and_swap variants to minimize adding barriers. */
 #if defined(AO_HAVE_short_compare_and_swap_full) \
     && !defined(AO_HAVE_short_fetch_and_add_full)
   AO_INLINE unsigned/**/short
 # define AO_HAVE_int_compare_and_swap_release
 #endif
 
+#if defined(AO_HAVE_int_fetch_compare_and_swap) \
+    && !defined(AO_HAVE_int_compare_and_swap)
+  AO_INLINE int
+  AO_int_compare_and_swap(volatile unsigned *addr, unsigned old_val,
+                            unsigned new_val)
+  {
+    return AO_int_fetch_compare_and_swap(addr, old_val, new_val) == old_val;
+  }
+# define AO_HAVE_int_compare_and_swap
+#endif
+
 /* int_fetch_and_add */
+/* We first try to implement fetch_and_add variants in terms of the     */
+/* corresponding compare_and_swap variants to minimize adding barriers. */
 #if defined(AO_HAVE_int_compare_and_swap_full) \
     && !defined(AO_HAVE_int_fetch_and_add_full)
   AO_INLINE unsigned
index 5f5bb9ab77eb5a2adb685d28f147842ed085f47a..b56430efb48c37cd3cff0b86bf1f852d3925f7fa 100644 (file)
 # define AO_HAVE_XSIZE_compare_and_swap_release
 #endif
 
+#if defined(AO_HAVE_XSIZE_fetch_compare_and_swap) \
+    && !defined(AO_HAVE_XSIZE_compare_and_swap)
+  AO_INLINE int
+  AO_XSIZE_compare_and_swap(volatile XCTYPE *addr, XCTYPE old_val,
+                            XCTYPE new_val)
+  {
+    return AO_XSIZE_fetch_compare_and_swap(addr, old_val, new_val) == old_val;
+  }
+# define AO_HAVE_XSIZE_compare_and_swap
+#endif
+
 /* XSIZE_fetch_and_add */
+/* We first try to implement fetch_and_add variants in terms of the     */
+/* corresponding compare_and_swap variants to minimize adding barriers. */
 #if defined(AO_HAVE_XSIZE_compare_and_swap_full) \
     && !defined(AO_HAVE_XSIZE_fetch_and_add_full)
   AO_INLINE XCTYPE