]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/aarch64/atomic-machine.h
1 /* Copyright (C) 2003-2016 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 <http://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
42 /* Compare and exchange.
43 For all "bool" routines, we return FALSE if exchange succesful. */
45 # define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \
47 typeof (*mem) __oldval = (oldval); \
48 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
49 model, __ATOMIC_RELAXED); \
52 # define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \
54 typeof (*mem) __oldval = (oldval); \
55 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
56 model, __ATOMIC_RELAXED); \
59 # define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \
61 typeof (*mem) __oldval = (oldval); \
62 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
63 model, __ATOMIC_RELAXED); \
66 # define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \
68 typeof (*mem) __oldval = (oldval); \
69 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
70 model, __ATOMIC_RELAXED); \
73 # define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \
75 typeof (*mem) __oldval = (oldval); \
76 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
77 model, __ATOMIC_RELAXED); \
81 # define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \
83 typeof (*mem) __oldval = (oldval); \
84 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
85 model, __ATOMIC_RELAXED); \
89 # define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \
91 typeof (*mem) __oldval = (oldval); \
92 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
93 model, __ATOMIC_RELAXED); \
97 # define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \
99 typeof (*mem) __oldval = (oldval); \
100 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
101 model, __ATOMIC_RELAXED); \
106 /* Compare and exchange with "acquire" semantics, ie barrier after. */
108 # define atomic_compare_and_exchange_bool_acq(mem, new, old) \
109 __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
110 mem, new, old, __ATOMIC_ACQUIRE)
112 # define atomic_compare_and_exchange_val_acq(mem, new, old) \
113 __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
114 mem, new, old, __ATOMIC_ACQUIRE)
116 /* Compare and exchange with "release" semantics, ie barrier before. */
118 # define atomic_compare_and_exchange_bool_rel(mem, new, old) \
119 __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
120 mem, new, old, __ATOMIC_RELEASE)
122 # define atomic_compare_and_exchange_val_rel(mem, new, old) \
123 __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
124 mem, new, old, __ATOMIC_RELEASE)
127 /* Atomic exchange (without compare). */
129 # define __arch_exchange_8_int(mem, newval, model) \
130 __atomic_exchange_n (mem, newval, model)
132 # define __arch_exchange_16_int(mem, newval, model) \
133 __atomic_exchange_n (mem, newval, model)
135 # define __arch_exchange_32_int(mem, newval, model) \
136 __atomic_exchange_n (mem, newval, model)
138 # define __arch_exchange_64_int(mem, newval, model) \
139 __atomic_exchange_n (mem, newval, model)
141 # define atomic_exchange_acq(mem, value) \
142 __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_ACQUIRE)
144 # define atomic_exchange_rel(mem, value) \
145 __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_RELEASE)
148 /* Atomically add value and return the previous (unincremented) value. */
150 # define __arch_exchange_and_add_8_int(mem, value, model) \
151 __atomic_fetch_add (mem, value, model)
153 # define __arch_exchange_and_add_16_int(mem, value, model) \
154 __atomic_fetch_add (mem, value, model)
156 # define __arch_exchange_and_add_32_int(mem, value, model) \
157 __atomic_fetch_add (mem, value, model)
159 # define __arch_exchange_and_add_64_int(mem, value, model) \
160 __atomic_fetch_add (mem, value, model)
162 # define atomic_exchange_and_add_acq(mem, value) \
163 __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
166 # define atomic_exchange_and_add_rel(mem, value) \
167 __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
171 #define atomic_full_barrier() __sync_synchronize()