summary refs log tree commit diff
path: root/include/atomic.h
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-02-17 18:52:09 +0000
committerUlrich Drepper <drepper@redhat.com>2006-02-17 18:52:09 +0000
commitf1740bc4e3566cad7620e3b36ca00c0c846ec398 (patch)
treea5d315fd5872aba244a5fa63c1bd864f101b9638 /include/atomic.h
parenta7245bf5271d49ed6d13d242801e50ae9911d072 (diff)
downloadglibc-f1740bc4e3566cad7620e3b36ca00c0c846ec398.tar.gz
glibc-f1740bc4e3566cad7620e3b36ca00c0c846ec398.tar.xz
glibc-f1740bc4e3566cad7620e3b36ca00c0c846ec398.zip
* include/atomic.h (atomic_and, atomic_or): Define.
Diffstat (limited to 'include/atomic.h')
-rw-r--r--include/atomic.h37
1 files changed, 36 insertions, 1 deletions
diff --git a/include/atomic.h b/include/atomic.h
index 8b76435a81..a1598e3850 100644
--- a/include/atomic.h
+++ b/include/atomic.h
@@ -1,5 +1,5 @@
 /* Internal macros for atomic operations for GNU C Library.
-   Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -273,6 +273,41 @@
      __oldval & __mask; })
 #endif
 
+/* Atomically *mem &= mask and return the old value of *mem.  */
+#ifndef atomic_and
+# define atomic_and(mem, mask) \
+  ({ __typeof (*(mem)) __oldval;					      \
+     __typeof (mem) __memp = (mem);					      \
+     __typeof (*(mem)) __mask = (mask);					      \
+									      \
+     do									      \
+       __oldval = (*__memp);						      \
+     while (__builtin_expect (atomic_compare_and_exchange_bool_acq (__memp,   \
+								    __oldval  \
+								    & __mask, \
+								    __oldval),\
+			      0));					      \
+									      \
+     __oldval; })
+#endif
+
+/* Atomically *mem |= mask and return the old value of *mem.  */
+#ifndef atomic_or
+# define atomic_or(mem, mask) \
+  ({ __typeof (*(mem)) __oldval;					      \
+     __typeof (mem) __memp = (mem);					      \
+     __typeof (*(mem)) __mask = (mask);					      \
+									      \
+     do									      \
+       __oldval = (*__memp);						      \
+     while (__builtin_expect (atomic_compare_and_exchange_bool_acq (__memp,   \
+								    __oldval  \
+								    | __mask, \
+								    __oldval),\
+			      0));					      \
+									      \
+     __oldval; })
+#endif
 
 #ifndef atomic_full_barrier
 # define atomic_full_barrier() __asm ("" ::: "memory")