1
/* Copyright (C) 2003-2012 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_BITS_ATOMIC_H
20
#define _AARCH64_BITS_ATOMIC_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;
40
/* Compare and exchange.
41
For all "bool" routines, we return FALSE if exchange succesful. */
43
# define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \
45
typeof (*mem) __oldval = (oldval); \
46
!__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
47
model, __ATOMIC_RELAXED); \
50
# define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \
52
typeof (*mem) __oldval = (oldval); \
53
!__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
54
model, __ATOMIC_RELAXED); \
57
# define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \
59
typeof (*mem) __oldval = (oldval); \
60
!__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
61
model, __ATOMIC_RELAXED); \
64
# define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \
66
typeof (*mem) __oldval = (oldval); \
67
!__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
68
model, __ATOMIC_RELAXED); \
71
# define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \
73
typeof (*mem) __oldval = (oldval); \
74
__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
75
model, __ATOMIC_RELAXED); \
79
# define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \
81
typeof (*mem) __oldval = (oldval); \
82
__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
83
model, __ATOMIC_RELAXED); \
87
# define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \
89
typeof (*mem) __oldval = (oldval); \
90
__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
91
model, __ATOMIC_RELAXED); \
95
# define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \
97
typeof (*mem) __oldval = (oldval); \
98
__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
99
model, __ATOMIC_RELAXED); \
104
/* Compare and exchange with "acquire" semantics, ie barrier after. */
106
# define atomic_compare_and_exchange_bool_acq(mem, new, old) \
107
__atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
108
mem, new, old, __ATOMIC_ACQUIRE)
110
# define atomic_compare_and_exchange_val_acq(mem, new, old) \
111
__atomic_val_bysize (__arch_compare_and_exchange_val, int, \
112
mem, new, old, __ATOMIC_ACQUIRE)
114
/* Compare and exchange with "release" semantics, ie barrier before. */
116
# define atomic_compare_and_exchange_bool_rel(mem, new, old) \
117
__atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
118
mem, new, old, __ATOMIC_RELEASE)
120
# define atomic_compare_and_exchange_val_rel(mem, new, old) \
121
__atomic_val_bysize (__arch_compare_and_exchange_val, int, \
122
mem, new, old, __ATOMIC_RELEASE)
125
/* Atomic exchange (without compare). */
127
# define __arch_exchange_8_int(mem, newval, model) \
128
__atomic_exchange_n (mem, newval, model)
130
# define __arch_exchange_16_int(mem, newval, model) \
131
__atomic_exchange_n (mem, newval, model)
133
# define __arch_exchange_32_int(mem, newval, model) \
134
__atomic_exchange_n (mem, newval, model)
136
# define __arch_exchange_64_int(mem, newval, model) \
137
__atomic_exchange_n (mem, newval, model)
139
# define atomic_exchange_acq(mem, value) \
140
__atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_ACQUIRE)
142
# define atomic_exchange_rel(mem, value) \
143
__atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_RELEASE)
146
/* Atomically add value and return the previous (unincremented) value. */
148
# define __arch_exchange_and_add_8_int(mem, value, model) \
149
__atomic_fetch_add (mem, value, model)
151
# define __arch_exchange_and_add_16_int(mem, value, model) \
152
__atomic_fetch_add (mem, value, model)
154
# define __arch_exchange_and_add_32_int(mem, value, model) \
155
__atomic_fetch_add (mem, value, model)
157
# define __arch_exchange_and_add_64_int(mem, value, model) \
158
__atomic_fetch_add (mem, value, model)
160
# define atomic_exchange_and_add_acq(mem, value) \
161
__atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
164
# define atomic_exchange_and_add_rel(mem, value) \
165
__atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
169
#define atomic_full_barrier() __sync_synchronize()