1 /* Copyright (C) 2003-2021 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3 
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8 
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library.  If not, see
16    <https://www.gnu.org/licenses/>.  */
17 
18 #ifndef _ATOMIC_MACHINE_H
19 #define _ATOMIC_MACHINE_H	1
20 
21 /* If we have just non-atomic operations, we can as well make them wide.  */
22 #define __HAVE_64B_ATOMICS 1
23 #define USE_ATOMIC_COMPILER_BUILTINS 0
24 
25 /* XXX Is this actually correct?  */
26 #define ATOMIC_EXCHANGE_USES_CAS 1
27 
28 /* The only basic operation needed is compare and exchange.  */
29 #define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
30   ({ __typeof (mem) __gmemp = (mem);				      \
31      __typeof (*mem) __gret = *__gmemp;				      \
32      __typeof (*mem) __gnewval = (newval);			      \
33 								      \
34      if (__gret == (oldval))					      \
35        *__gmemp = __gnewval;					      \
36      __gret; })
37 
38 #define atomic_compare_and_exchange_bool_acq(mem, newval, oldval) \
39   ({ __typeof (mem) __gmemp = (mem);				      \
40      __typeof (*mem) __gnewval = (newval);			      \
41 								      \
42      *__gmemp == (oldval) ? (*__gmemp = __gnewval, 0) : 1; })
43 
44 #endif
45