Define atomic_max and atomic_min.
[kopensolaris-gnu/glibc.git] / include / atomic.h
index 299f196..8b76435 100644 (file)
@@ -1,5 +1,5 @@
 /* Internal macros for atomic operations for GNU C Library.
-   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -71,8 +71,8 @@
 
 
 #ifndef atomic_compare_and_exchange_val_rel
-# define atomic_compare_and_exchange_val_rel(mem, oldval, newval)            \
-  atomic_compare_and_exchange_val_acq (mem, oldval, newval)
+# define atomic_compare_and_exchange_val_rel(mem, newval, oldval)            \
+  atomic_compare_and_exchange_val_acq (mem, newval, oldval)
 #endif
 
 
@@ -95,8 +95,8 @@
 
 
 #ifndef atomic_compare_and_exchange_bool_rel
-# define atomic_compare_and_exchange_bool_rel(mem, oldval, newval) \
-  atomic_compare_and_exchange_bool_acq (mem, oldval, newval)
+# define atomic_compare_and_exchange_bool_rel(mem, newval, oldval) \
+  atomic_compare_and_exchange_bool_acq (mem, newval, oldval)
 #endif
 
 
      __typeof (*(mem)) __value = (newvalue);                                 \
                                                                              \
      do                                                                              \
-       __oldval = (*__memp);                                                 \
+       __oldval = *__memp;                                                   \
      while (__builtin_expect (atomic_compare_and_exchange_bool_acq (__memp,   \
                                                                    __value,  \
                                                                    __oldval),\
      __typeof (*(mem)) __value = (value);                                    \
                                                                              \
      do                                                                              \
-       __oldval = (*__memp);                                                 \
+       __oldval = *__memp;                                                   \
      while (__builtin_expect (atomic_compare_and_exchange_bool_acq (__memp,   \
                                                                    __oldval  \
                                                                    + __value,\
 #endif
 
 
+
+#ifndef atomic_max
+# define atomic_max(mem, value) \
+  do {                                                                       \
+    __typeof (*(mem)) __oldval;                                                      \
+    __typeof (mem) __memp = (mem);                                           \
+    __typeof (*(mem)) __value = (value);                                     \
+    do {                                                                     \
+      __oldval = *__memp;                                                    \
+      if (__oldval >= __value)                                               \
+       break;                                                                \
+    } while (__builtin_expect (atomic_compare_and_exchange_bool_acq (__memp,  \
+                                                                    __value, \
+                                                                    __oldval),\
+                              0));                                           \
+  } while (0)
+#endif
+
+#ifndef atomic_min
+# define atomic_min(mem, value) \
+  do {                                                                       \
+    __typeof (*(mem)) __oldval;                                                      \
+    __typeof (mem) __memp = (mem);                                           \
+    __typeof (*(mem)) __value = (value);                                     \
+    do {                                                                     \
+      __oldval = *__memp;                                                    \
+      if (__oldval <= __value)                                               \
+       break;                                                                \
+    } while (__builtin_expect (atomic_compare_and_exchange_bool_acq (__memp,  \
+                                                                    __value, \
+                                                                    __oldval),\
+                              0));                                           \
+  } while (0)
+#endif
+
 #ifndef atomic_add
 # define atomic_add(mem, value) (void) atomic_exchange_and_add ((mem), (value))
 #endif
 #endif
 
 
+#ifndef atomic_increment_val
+# define atomic_increment_val(mem) (atomic_exchange_and_add ((mem), 1) + 1)
+#endif
+
+
 /* Add one to *MEM and return true iff it's now zero.  */
 #ifndef atomic_increment_and_test
 # define atomic_increment_and_test(mem) \
 #endif
 
 
+#ifndef atomic_decrement_val
+# define atomic_decrement_val(mem) (atomic_exchange_and_add ((mem), -1) - 1)
+#endif
+
+
 /* Subtract 1 from *MEM and return true iff it's now zero.  */
 #ifndef atomic_decrement_and_test
 # define atomic_decrement_and_test(mem) \
 # define atomic_write_barrier() atomic_full_barrier ()
 #endif
 
+
+#ifndef atomic_delay
+# define atomic_delay() do { /* nothing */ } while (0)
+#endif
+
 #endif /* atomic.h */