~ubuntu-branches/ubuntu/trusty/eglibc/trusty

« back to all changes in this revision

Viewing changes to ports/sysdeps/unix/sysv/linux/arm/nptl/bits/atomic.h

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-01-10 18:39:35 UTC
  • mfrom: (1.5.2) (4.4.24 experimental)
  • Revision ID: package-import@ubuntu.com-20130110183935-afsgfxkmg7wk5eaj
Tags: 2.17-0ubuntu1
* Merge with Debian, bringing in a new upstream and many small fixes:
  - patches/any/cvs-malloc-deadlock.diff: Dropped, merged upstream.
  - patches/ubuntu/lddebug-scopes.diff: Rebase for upstream changes.
  - patches/ubuntu/local-CVE-2012-3406.diff: Rebased against upstream.
  - patches/ubuntu/no-asm-mtune-i686.diff: Fixed in recent binutils.
* This upstream merge fixes a nasty hang in pulseaudio (LP: #1085342)
* Bump MIN_KERNEL_SUPPORTED to 2.6.32 on ARM, now that we no longer
  have to support shonky 2.6.31 kernels on imx51 babbage builders.
* Drop patches/ubuntu/local-disable-nscd-host-caching.diff, as these
  issues were apparently resolved upstream a while ago (LP: #613662)
* Fix the compiled-in bug URL to point to launchpad.net, not Debian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
2
 
   This file is part of the GNU C Library.
3
 
 
4
 
   The GNU C Library is free software; you can redistribute it and/or
5
 
   modify it under the terms of the GNU Lesser General Public
6
 
   License as published by the Free Software Foundation; either
7
 
   version 2.1 of the License, or (at your option) any later version.
8
 
 
9
 
   The GNU C Library is distributed in the hope that it will be useful,
10
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
   Lesser General Public License for more details.
13
 
 
14
 
   You should have received a copy of the GNU Lesser General Public
15
 
   License along with the GNU C Library.  If not, see
16
 
   <http://www.gnu.org/licenses/>.  */
17
 
 
18
 
#include <stdint.h>
19
 
 
20
 
 
21
 
typedef int8_t atomic8_t;
22
 
typedef uint8_t uatomic8_t;
23
 
typedef int_fast8_t atomic_fast8_t;
24
 
typedef uint_fast8_t uatomic_fast8_t;
25
 
 
26
 
typedef int32_t atomic32_t;
27
 
typedef uint32_t uatomic32_t;
28
 
typedef int_fast32_t atomic_fast32_t;
29
 
typedef uint_fast32_t uatomic_fast32_t;
30
 
 
31
 
typedef intptr_t atomicptr_t;
32
 
typedef uintptr_t uatomicptr_t;
33
 
typedef intmax_t atomic_max_t;
34
 
typedef uintmax_t uatomic_max_t;
35
 
 
36
 
void __arm_link_error (void);
37
 
 
38
 
/* Use the atomic builtins provided by GCC in case the backend provides
39
 
   a pattern to do this efficiently.  */
40
 
 
41
 
#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
42
 
#define atomic_full_barrier() __sync_synchronize ()
43
 
#elif defined __thumb2__
44
 
#define atomic_full_barrier() \
45
 
     __asm__ __volatile__                                                     \
46
 
             ("movw\tip, #0x0fa0\n\t"                                         \
47
 
              "movt\tip, #0xffff\n\t"                                         \
48
 
              "blx\tip"                                                       \
49
 
              : : : "ip", "lr", "cc", "memory");
50
 
#else
51
 
#define atomic_full_barrier() \
52
 
     __asm__ __volatile__                                                     \
53
 
             ("mov\tip, #0xffff0fff\n\t"                                      \
54
 
              "mov\tlr, pc\n\t"                                               \
55
 
              "add\tpc, ip, #(0xffff0fa0 - 0xffff0fff)"                       \
56
 
              : : : "ip", "lr", "cc", "memory");
57
 
#endif
58
 
 
59
 
/* Atomic compare and exchange.  This sequence relies on the kernel to
60
 
   provide a compare and exchange operation which is atomic on the
61
 
   current architecture, either via cleverness on pre-ARMv6 or via
62
 
   ldrex / strex on ARMv6.  */
63
 
 
64
 
#define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
65
 
  ({ __arm_link_error (); oldval; })
66
 
 
67
 
#define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
68
 
  ({ __arm_link_error (); oldval; })
69
 
 
70
 
#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
71
 
#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
72
 
  __sync_val_compare_and_swap ((mem), (oldval), (newval))
73
 
 
74
 
/* It doesn't matter what register is used for a_oldval2, but we must
75
 
   specify one to work around GCC PR rtl-optimization/21223.  Otherwise
76
 
   it may cause a_oldval or a_tmp to be moved to a different register.  */
77
 
 
78
 
#elif defined __thumb2__
79
 
/* Thumb-2 has ldrex/strex.  However it does not have barrier instructions,
80
 
   so we still need to use the kernel helper.  */
81
 
#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
82
 
  ({ register __typeof (oldval) a_oldval asm ("r0");                          \
83
 
     register __typeof (oldval) a_newval asm ("r1") = (newval);               \
84
 
     register __typeof (mem) a_ptr asm ("r2") = (mem);                        \
85
 
     register __typeof (oldval) a_tmp asm ("r3");                             \
86
 
     register __typeof (oldval) a_oldval2 asm ("r4") = (oldval);              \
87
 
     __asm__ __volatile__                                                     \
88
 
             ("0:\tldr\t%[tmp],[%[ptr]]\n\t"                                  \
89
 
              "cmp\t%[tmp], %[old2]\n\t"                                      \
90
 
              "bne\t1f\n\t"                                                   \
91
 
              "mov\t%[old], %[old2]\n\t"                                      \
92
 
              "movw\t%[tmp], #0x0fc0\n\t"                                     \
93
 
              "movt\t%[tmp], #0xffff\n\t"                                     \
94
 
              "blx\t%[tmp]\n\t"                                               \
95
 
              "bcc\t0b\n\t"                                                   \
96
 
              "mov\t%[tmp], %[old2]\n\t"                                      \
97
 
              "1:"                                                            \
98
 
              : [old] "=&r" (a_oldval), [tmp] "=&r" (a_tmp)                   \
99
 
              : [new] "r" (a_newval), [ptr] "r" (a_ptr),                      \
100
 
                [old2] "r" (a_oldval2)                                        \
101
 
              : "ip", "lr", "cc", "memory");                                  \
102
 
     a_tmp; })
103
 
#else
104
 
#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
105
 
  ({ register __typeof (oldval) a_oldval asm ("r0");                          \
106
 
     register __typeof (oldval) a_newval asm ("r1") = (newval);               \
107
 
     register __typeof (mem) a_ptr asm ("r2") = (mem);                        \
108
 
     register __typeof (oldval) a_tmp asm ("r3");                             \
109
 
     register __typeof (oldval) a_oldval2 asm ("r4") = (oldval);              \
110
 
     __asm__ __volatile__                                                     \
111
 
             ("0:\tldr\t%[tmp],[%[ptr]]\n\t"                                  \
112
 
              "cmp\t%[tmp], %[old2]\n\t"                                      \
113
 
              "bne\t1f\n\t"                                                   \
114
 
              "mov\t%[old], %[old2]\n\t"                                      \
115
 
              "mov\t%[tmp], #0xffff0fff\n\t"                                  \
116
 
              "mov\tlr, pc\n\t"                                               \
117
 
              "add\tpc, %[tmp], #(0xffff0fc0 - 0xffff0fff)\n\t"               \
118
 
              "bcc\t0b\n\t"                                                   \
119
 
              "mov\t%[tmp], %[old2]\n\t"                                      \
120
 
              "1:"                                                            \
121
 
              : [old] "=&r" (a_oldval), [tmp] "=&r" (a_tmp)                   \
122
 
              : [new] "r" (a_newval), [ptr] "r" (a_ptr),                      \
123
 
                [old2] "r" (a_oldval2)                                        \
124
 
              : "ip", "lr", "cc", "memory");                                  \
125
 
     a_tmp; })
126
 
#endif
127
 
 
128
 
#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
129
 
  ({ __arm_link_error (); oldval; })