]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/arm/atomic-machine.h
Remove atomic_compare_and_exchange_bool_rel.
[thirdparty/glibc.git] / sysdeps / arm / atomic-machine.h
1 /* Atomic operations. Pure ARM version.
2 Copyright (C) 2002-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #include <stdint.h>
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 #define __HAVE_64B_ATOMICS 0
37 #define USE_ATOMIC_COMPILER_BUILTINS 0
38
39 void __arm_link_error (void);
40
41 #ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
42 # define atomic_full_barrier() __sync_synchronize ()
43 #else
44 # define atomic_full_barrier() __arm_assisted_full_barrier ()
45 #endif
46
47 /* An OS-specific atomic-machine.h file will define this macro if
48 the OS can provide something. If not, we'll fail to build
49 with a compiler that doesn't supply the operation. */
50 #ifndef __arm_assisted_full_barrier
51 # define __arm_assisted_full_barrier() __arm_link_error()
52 #endif
53
54 /* Use the atomic builtins provided by GCC in case the backend provides
55 a pattern to do this efficiently. */
56 #ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
57
58 # define atomic_exchange_acq(mem, value) \
59 __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_ACQUIRE)
60
61 # define atomic_exchange_rel(mem, value) \
62 __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_RELEASE)
63
64 /* Atomic exchange (without compare). */
65
66 # define __arch_exchange_8_int(mem, newval, model) \
67 (__arm_link_error (), (typeof (*mem)) 0)
68
69 # define __arch_exchange_16_int(mem, newval, model) \
70 (__arm_link_error (), (typeof (*mem)) 0)
71
72 # define __arch_exchange_32_int(mem, newval, model) \
73 __atomic_exchange_n (mem, newval, model)
74
75 # define __arch_exchange_64_int(mem, newval, model) \
76 (__arm_link_error (), (typeof (*mem)) 0)
77
78 /* Compare and exchange with "acquire" semantics, ie barrier after. */
79
80 # define atomic_compare_and_exchange_bool_acq(mem, new, old) \
81 __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
82 mem, new, old, __ATOMIC_ACQUIRE)
83
84 # define atomic_compare_and_exchange_val_acq(mem, new, old) \
85 __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
86 mem, new, old, __ATOMIC_ACQUIRE)
87
88 /* Compare and exchange with "release" semantics, ie barrier before. */
89
90 # define atomic_compare_and_exchange_val_rel(mem, new, old) \
91 __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
92 mem, new, old, __ATOMIC_RELEASE)
93
94 /* Compare and exchange.
95 For all "bool" routines, we return FALSE if exchange succesful. */
96
97 # define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \
98 ({__arm_link_error (); 0; })
99
100 # define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \
101 ({__arm_link_error (); 0; })
102
103 # define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \
104 ({ \
105 typeof (*mem) __oldval = (oldval); \
106 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
107 model, __ATOMIC_RELAXED); \
108 })
109
110 # define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \
111 ({__arm_link_error (); 0; })
112
113 # define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \
114 ({__arm_link_error (); oldval; })
115
116 # define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \
117 ({__arm_link_error (); oldval; })
118
119 # define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \
120 ({ \
121 typeof (*mem) __oldval = (oldval); \
122 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
123 model, __ATOMIC_RELAXED); \
124 __oldval; \
125 })
126
127 # define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \
128 ({__arm_link_error (); oldval; })
129
130 #else
131 # define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
132 __arm_assisted_compare_and_exchange_val_32_acq ((mem), (newval), (oldval))
133 #endif
134
135 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
136 /* We don't support atomic operations on any non-word types.
137 So make them link errors. */
138 # define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
139 ({ __arm_link_error (); oldval; })
140
141 # define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
142 ({ __arm_link_error (); oldval; })
143
144 # define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
145 ({ __arm_link_error (); oldval; })
146 #endif
147
148 /* An OS-specific atomic-machine.h file will define this macro if
149 the OS can provide something. If not, we'll fail to build
150 with a compiler that doesn't supply the operation. */
151 #ifndef __arm_assisted_compare_and_exchange_val_32_acq
152 # define __arm_assisted_compare_and_exchange_val_32_acq(mem, newval, oldval) \
153 ({ __arm_link_error (); oldval; })
154 #endif