Back to index

glibc  2.9
atomic.h
Go to the documentation of this file.
00001 /* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <stdint.h>
00020 #include <sysdep.h>
00021 
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 int32_t atomic32_t;
00029 typedef uint32_t uatomic32_t;
00030 typedef int_fast32_t atomic_fast32_t;
00031 typedef uint_fast32_t uatomic_fast32_t;
00032 
00033 typedef intptr_t atomicptr_t;
00034 typedef uintptr_t uatomicptr_t;
00035 typedef intmax_t atomic_max_t;
00036 typedef uintmax_t uatomic_max_t;
00037 
00038 void __arm_link_error (void);
00039 
00040 #define atomic_full_barrier() \
00041      __asm__ __volatile__                                            \
00042             ("mov\tip, #0xffff0fff\n\t"                              \
00043              "mov\tlr, pc\n\t"                                              \
00044              "add\tpc, ip, #(0xffff0fa0 - 0xffff0fff)"                      \
00045              : : : "ip", "lr", "cc", "memory");
00046 
00047 /* Atomic compare and exchange.  This sequence relies on the kernel to
00048    provide a compare and exchange operation which is atomic on the
00049    current architecture, either via cleverness on pre-ARMv6 or via
00050    ldrex / strex on ARMv6.  */
00051 
00052 #define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
00053   ({ __arm_link_error (); oldval; })
00054 
00055 #define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
00056   ({ __arm_link_error (); oldval; })
00057 
00058 /* It doesn't matter what register is used for a_oldval2, but we must
00059    specify one to work around GCC PR rtl-optimization/21223.  Otherwise
00060    it may cause a_oldval or a_tmp to be moved to a different register.  */
00061 
00062 #define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
00063   ({ register __typeof (oldval) a_oldval asm ("r0");                        \
00064      register __typeof (oldval) a_newval asm ("r1") = (newval);                    \
00065      register __typeof (mem) a_ptr asm ("r2") = (mem);                      \
00066      register __typeof (oldval) a_tmp asm ("r3");                           \
00067      register __typeof (oldval) a_oldval2 asm ("r4") = (oldval);            \
00068      __asm__ __volatile__                                            \
00069             ("0:\tldr\t%[tmp],[%[ptr]]\n\t"                                 \
00070              "cmp\t%[tmp], %[old2]\n\t"                              \
00071              "bne\t1f\n\t"                                           \
00072              "mov\t%[old], %[old2]\n\t"                              \
00073              "mov\t%[tmp], #0xffff0fff\n\t"                                 \
00074              "mov\tlr, pc\n\t"                                              \
00075              "add\tpc, %[tmp], #(0xffff0fc0 - 0xffff0fff)\n\t"              \
00076              "bcc\t0b\n\t"                                           \
00077              "mov\t%[tmp], %[old2]\n\t"                              \
00078              "1:"                                                    \
00079              : [old] "=&r" (a_oldval), [tmp] "=&r" (a_tmp)                  \
00080              : [new] "r" (a_newval), [ptr] "r" (a_ptr),              \
00081               [old2] "r" (a_oldval2)                                        \
00082              : "ip", "lr", "cc", "memory");                                 \
00083      a_tmp; })
00084 
00085 #define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
00086   ({ __arm_link_error (); oldval; })