]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/aarch64/atomic-machine.h
06f76dc23b2ac91907fd8f41f9fdf38d9bbe8476
1 /* Copyright (C) 2003-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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 <https://www.gnu.org/licenses/>. */
19 #ifndef _AARCH64_ATOMIC_MACHINE_H
20 #define _AARCH64_ATOMIC_MACHINE_H 1
24 typedef int8_t atomic8_t
;
25 typedef int16_t atomic16_t
;
26 typedef int32_t atomic32_t
;
27 typedef int64_t atomic64_t
;
29 typedef uint8_t uatomic8_t
;
30 typedef uint16_t uatomic16_t
;
31 typedef uint32_t uatomic32_t
;
32 typedef uint64_t uatomic64_t
;
34 typedef intptr_t atomicptr_t
;
35 typedef uintptr_t uatomicptr_t
;
36 typedef intmax_t atomic_max_t
;
37 typedef uintmax_t uatomic_max_t
;
39 #define __HAVE_64B_ATOMICS 1
40 #define USE_ATOMIC_COMPILER_BUILTINS 1
41 #define ATOMIC_EXCHANGE_USES_CAS 0
43 /* Compare and exchange.
44 For all "bool" routines, we return FALSE if exchange succesful. */
46 # define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \
48 typeof (*mem) __oldval = (oldval); \
49 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
50 model, __ATOMIC_RELAXED); \
53 # define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \
55 typeof (*mem) __oldval = (oldval); \
56 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
57 model, __ATOMIC_RELAXED); \
60 # define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \
62 typeof (*mem) __oldval = (oldval); \
63 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
64 model, __ATOMIC_RELAXED); \
67 # define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \
69 typeof (*mem) __oldval = (oldval); \
70 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
71 model, __ATOMIC_RELAXED); \
74 # define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \
76 typeof (*mem) __oldval = (oldval); \
77 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
78 model, __ATOMIC_RELAXED); \
82 # define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \
84 typeof (*mem) __oldval = (oldval); \
85 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
86 model, __ATOMIC_RELAXED); \
90 # define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \
92 typeof (*mem) __oldval = (oldval); \
93 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
94 model, __ATOMIC_RELAXED); \
98 # define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \
100 typeof (*mem) __oldval = (oldval); \
101 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
102 model, __ATOMIC_RELAXED); \
107 /* Compare and exchange with "acquire" semantics, ie barrier after. */
109 # define atomic_compare_and_exchange_bool_acq(mem, new, old) \
110 __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
111 mem, new, old, __ATOMIC_ACQUIRE)
113 # define atomic_compare_and_exchange_val_acq(mem, new, old) \
114 __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
115 mem, new, old, __ATOMIC_ACQUIRE)
117 /* Compare and exchange with "release" semantics, ie barrier before. */
119 # define atomic_compare_and_exchange_val_rel(mem, new, old) \
120 __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
121 mem, new, old, __ATOMIC_RELEASE)
124 /* Atomic exchange (without compare). */
126 # define __arch_exchange_8_int(mem, newval, model) \
127 __atomic_exchange_n (mem, newval, model)
129 # define __arch_exchange_16_int(mem, newval, model) \
130 __atomic_exchange_n (mem, newval, model)
132 # define __arch_exchange_32_int(mem, newval, model) \
133 __atomic_exchange_n (mem, newval, model)
135 # define __arch_exchange_64_int(mem, newval, model) \
136 __atomic_exchange_n (mem, newval, model)
138 # define atomic_exchange_acq(mem, value) \
139 __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_ACQUIRE)
141 # define atomic_exchange_rel(mem, value) \
142 __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_RELEASE)
145 /* Atomically add value and return the previous (unincremented) value. */
147 # define __arch_exchange_and_add_8_int(mem, value, model) \
148 __atomic_fetch_add (mem, value, model)
150 # define __arch_exchange_and_add_16_int(mem, value, model) \
151 __atomic_fetch_add (mem, value, model)
153 # define __arch_exchange_and_add_32_int(mem, value, model) \
154 __atomic_fetch_add (mem, value, model)
156 # define __arch_exchange_and_add_64_int(mem, value, model) \
157 __atomic_fetch_add (mem, value, model)
159 # define atomic_exchange_and_add_acq(mem, value) \
160 __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
163 # define atomic_exchange_and_add_rel(mem, value) \
164 __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
168 #define atomic_full_barrier() __sync_synchronize()