diff options
author | Ulrich Drepper <drepper@redhat.com> | 2006-02-17 18:52:09 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2006-02-17 18:52:09 +0000 |
commit | f1740bc4e3566cad7620e3b36ca00c0c846ec398 (patch) | |
tree | a5d315fd5872aba244a5fa63c1bd864f101b9638 /include/atomic.h | |
parent | a7245bf5271d49ed6d13d242801e50ae9911d072 (diff) | |
download | glibc-f1740bc4e3566cad7620e3b36ca00c0c846ec398.tar.gz |
* include/atomic.h (atomic_and, atomic_or): Define.
Diffstat (limited to 'include/atomic.h')
-rw-r--r-- | include/atomic.h | 37 |
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") |