Define atomic_max and atomic_min.
[kopensolaris-gnu/glibc.git] / include / atomic.h
index 8a23f6e..8b76435 100644 (file)
@@ -1,5 +1,5 @@
 /* Internal macros for atomic operations for GNU C Library.
-   Copyright (C) 2002, 2003, 2004 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.
 
      __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