1#ifndef ATOMIC_GCC_BUILTINS_INCLUDED
2#define ATOMIC_GCC_BUILTINS_INCLUDED
3
4/* Copyright (c) 2017 MariaDB Foundation
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; version 2 of the License.
9
10 This program 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
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
18
19
20#define MY_MEMORY_ORDER_RELAXED __ATOMIC_RELAXED
21#define MY_MEMORY_ORDER_CONSUME __ATOMIC_CONSUME
22#define MY_MEMORY_ORDER_ACQUIRE __ATOMIC_ACQUIRE
23#define MY_MEMORY_ORDER_RELEASE __ATOMIC_RELEASE
24#define MY_MEMORY_ORDER_ACQ_REL __ATOMIC_ACQ_REL
25#define MY_MEMORY_ORDER_SEQ_CST __ATOMIC_SEQ_CST
26
27#define my_atomic_store32_explicit(P, D, O) __atomic_store_n((P), (D), (O))
28#define my_atomic_store64_explicit(P, D, O) __atomic_store_n((P), (D), (O))
29#define my_atomic_storeptr_explicit(P, D, O) __atomic_store_n((P), (D), (O))
30
31#define my_atomic_load32_explicit(P, O) __atomic_load_n((P), (O))
32#define my_atomic_load64_explicit(P, O) __atomic_load_n((P), (O))
33#define my_atomic_loadptr_explicit(P, O) __atomic_load_n((P), (O))
34
35#define my_atomic_fas32_explicit(P, D, O) __atomic_exchange_n((P), (D), (O))
36#define my_atomic_fas64_explicit(P, D, O) __atomic_exchange_n((P), (D), (O))
37#define my_atomic_fasptr_explicit(P, D, O) __atomic_exchange_n((P), (D), (O))
38
39#define my_atomic_add32_explicit(P, A, O) __atomic_fetch_add((P), (A), (O))
40#define my_atomic_add64_explicit(P, A, O) __atomic_fetch_add((P), (A), (O))
41
42#define my_atomic_cas32_weak_explicit(P, E, D, S, F) \
43 __atomic_compare_exchange_n((P), (E), (D), 1, (S), (F))
44#define my_atomic_cas64_weak_explicit(P, E, D, S, F) \
45 __atomic_compare_exchange_n((P), (E), (D), 1, (S), (F))
46#define my_atomic_casptr_weak_explicit(P, E, D, S, F) \
47 __atomic_compare_exchange_n((P), (E), (D), 1, (S), (F))
48
49#define my_atomic_cas32_strong_explicit(P, E, D, S, F) \
50 __atomic_compare_exchange_n((P), (E), (D), 0, (S), (F))
51#define my_atomic_cas64_strong_explicit(P, E, D, S, F) \
52 __atomic_compare_exchange_n((P), (E), (D), 0, (S), (F))
53#define my_atomic_casptr_strong_explicit(P, E, D, S, F) \
54 __atomic_compare_exchange_n((P), (E), (D), 0, (S), (F))
55
56#define my_atomic_store32(P, D) __atomic_store_n((P), (D), __ATOMIC_SEQ_CST)
57#define my_atomic_store64(P, D) __atomic_store_n((P), (D), __ATOMIC_SEQ_CST)
58#define my_atomic_storeptr(P, D) __atomic_store_n((P), (D), __ATOMIC_SEQ_CST)
59
60#define my_atomic_load32(P) __atomic_load_n((P), __ATOMIC_SEQ_CST)
61#define my_atomic_load64(P) __atomic_load_n((P), __ATOMIC_SEQ_CST)
62#define my_atomic_loadptr(P) __atomic_load_n((P), __ATOMIC_SEQ_CST)
63
64#define my_atomic_fas32(P, D) __atomic_exchange_n((P), (D), __ATOMIC_SEQ_CST)
65#define my_atomic_fas64(P, D) __atomic_exchange_n((P), (D), __ATOMIC_SEQ_CST)
66#define my_atomic_fasptr(P, D) __atomic_exchange_n((P), (D), __ATOMIC_SEQ_CST)
67
68#define my_atomic_add32(P, A) __atomic_fetch_add((P), (A), __ATOMIC_SEQ_CST)
69#define my_atomic_add64(P, A) __atomic_fetch_add((P), (A), __ATOMIC_SEQ_CST)
70
71#define my_atomic_cas32(P, E, D) \
72 __atomic_compare_exchange_n((P), (E), (D), 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
73#define my_atomic_cas64(P, E, D) \
74 __atomic_compare_exchange_n((P), (E), (D), 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
75#define my_atomic_casptr(P, E, D) \
76 __atomic_compare_exchange_n((P), (E), (D), 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
77
78#endif /* ATOMIC_GCC_BUILTINS_INCLUDED */
79