1 /* Atomic operations. C-SKY version.
2 Copyright (C) 2018-2023 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 <https://www.gnu.org/licenses/>. */
18
19 #ifndef __CSKY_ATOMIC_H_
20 #define __CSKY_ATOMIC_H_
21
22 #define __HAVE_64B_ATOMICS 0
23 #define USE_ATOMIC_COMPILER_BUILTINS 1
24 #define ATOMIC_EXCHANGE_USES_CAS 1
25
26 #define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \
27 (abort (), 0)
28
29 #define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \
30 (abort (), 0)
31
32 #define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \
33 ({ \
34 typeof (*mem) __oldval = (oldval); \
35 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
36 model, __ATOMIC_RELAXED); \
37 })
38
39 #define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \
40 (abort (), 0)
41
42 #define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \
43 (abort (), (__typeof (*mem)) 0)
44
45 #define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \
46 (abort (), (__typeof (*mem)) 0)
47
48 #define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \
49 ({ \
50 typeof (*mem) __oldval = (oldval); \
51 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
52 model, __ATOMIC_RELAXED); \
53 __oldval; \
54 })
55
56 #define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \
57 (abort (), (__typeof (*mem)) 0)
58
59 #define atomic_compare_and_exchange_bool_acq(mem, new, old) \
60 __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
61 mem, new, old, __ATOMIC_ACQUIRE)
62
63 #define atomic_compare_and_exchange_val_acq(mem, new, old) \
64 __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
65 mem, new, old, __ATOMIC_ACQUIRE)
66
67 #endif /* atomic-machine.h */