Back to index

glibc  2.9
atomic.h
Go to the documentation of this file.
00001 /* Atomic operations.  sparc64 version.
00002    Copyright (C) 2003, 2006 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <stdint.h>
00022 
00023 typedef int8_t atomic8_t;
00024 typedef uint8_t uatomic8_t;
00025 typedef int_fast8_t atomic_fast8_t;
00026 typedef uint_fast8_t uatomic_fast8_t;
00027 
00028 typedef int16_t atomic16_t;
00029 typedef uint16_t uatomic16_t;
00030 typedef int_fast16_t atomic_fast16_t;
00031 typedef uint_fast16_t uatomic_fast16_t;
00032 
00033 typedef int32_t atomic32_t;
00034 typedef uint32_t uatomic32_t;
00035 typedef int_fast32_t atomic_fast32_t;
00036 typedef uint_fast32_t uatomic_fast32_t;
00037 
00038 typedef int64_t atomic64_t;
00039 typedef uint64_t uatomic64_t;
00040 typedef int_fast64_t atomic_fast64_t;
00041 typedef uint_fast64_t uatomic_fast64_t;
00042 
00043 typedef intptr_t atomicptr_t;
00044 typedef uintptr_t uatomicptr_t;
00045 typedef intmax_t atomic_max_t;
00046 typedef uintmax_t uatomic_max_t;
00047 
00048 
00049 #define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
00050   (abort (), (__typeof (*mem)) 0)
00051 
00052 #define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
00053   (abort (), (__typeof (*mem)) 0)
00054 
00055 #define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
00056 ({                                                                   \
00057   __typeof (*(mem)) __acev_tmp;                                             \
00058   __typeof (mem) __acev_mem = (mem);                                        \
00059   __asm __volatile ("cas [%4], %2, %0"                                      \
00060                   : "=r" (__acev_tmp), "=m" (*__acev_mem)                   \
00061                   : "r" (oldval), "m" (*__acev_mem), "r" (__acev_mem),      \
00062                     "0" (newval) : "memory");                               \
00063   __acev_tmp; })
00064 
00065 #define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
00066 ({                                                                   \
00067   __typeof (*(mem)) __acev_tmp;                                             \
00068   __typeof (mem) __acev_mem = (mem);                                        \
00069   __asm __volatile ("casx [%4], %2, %0"                                     \
00070                   : "=r" (__acev_tmp), "=m" (*__acev_mem)                   \
00071                   : "r" ((long) (oldval)), "m" (*__acev_mem),               \
00072                     "r" (__acev_mem), "0" ((long) (newval)) : "memory");    \
00073   __acev_tmp; })
00074 
00075 #define atomic_exchange_acq(mem, newvalue) \
00076   ({ __typeof (*(mem)) __oldval, __val;                                     \
00077      __typeof (mem) __memp = (mem);                                         \
00078      __typeof (*(mem)) __value = (newvalue);                                \
00079                                                                      \
00080      if (sizeof (*(mem)) == 4)                                              \
00081        __asm ("swap %0, %1"                                          \
00082              : "=m" (*__memp), "=r" (__oldval)                              \
00083              : "m" (*__memp), "1" (__value) : "memory");                    \
00084      else                                                            \
00085        {                                                             \
00086         __val = *__memp;                                             \
00087         do                                                           \
00088           {                                                          \
00089             __oldval = __val;                                               \
00090             __val = atomic_compare_and_exchange_val_acq (__memp, __value,    \
00091                                                    __oldval);        \
00092           }                                                          \
00093          while (__builtin_expect (__val != __oldval, 0));                   \
00094        }                                                             \
00095      __oldval; })
00096 
00097 #define atomic_compare_and_exchange_val_24_acq(mem, newval, oldval) \
00098   atomic_compare_and_exchange_val_acq (mem, newval, oldval)
00099 
00100 #define atomic_exchange_24_rel(mem, newval) \
00101   atomic_exchange_rel (mem, newval)
00102 
00103 #define atomic_full_barrier() \
00104   __asm __volatile ("membar #LoadLoad | #LoadStore"                         \
00105                        " | #StoreLoad | #StoreStore" : : : "memory")
00106 #define atomic_read_barrier() \
00107   __asm __volatile ("membar #LoadLoad | #LoadStore" : : : "memory")
00108 #define atomic_write_barrier() \
00109   __asm __volatile ("membar #StoreLoad | #StoreStore" : : : "memory")