1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Carlos O'Donell <carlos@baldric.uwo.ca>, 2005.
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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 #include <abort-instr.h>
23 #include <kernel-features.h>
25 /* We need EFAULT, ENONSYS, and EAGAIN */
26 #if !defined EFAULT && !defined ENOSYS && !defined EAGAIN
35 #ifndef _BITS_ATOMIC_H
36 #define _BITS_ATOMIC_H 1
38 typedef int8_t atomic8_t;
39 typedef uint8_t uatomic8_t;
40 typedef int_fast8_t atomic_fast8_t;
41 typedef uint_fast8_t uatomic_fast8_t;
43 typedef int32_t atomic32_t;
44 typedef uint32_t uatomic32_t;
45 typedef int_fast32_t atomic_fast32_t;
46 typedef uint_fast32_t uatomic_fast32_t;
48 typedef intptr_t atomicptr_t;
49 typedef uintptr_t uatomicptr_t;
50 typedef intmax_t atomic_max_t;
51 typedef uintmax_t uatomic_max_t;
58 /* Use the kernel atomic light weight syscalls on hppa */
61 /* Note r31 is the link register */
62 #define LWS_CLOBBER "r1", "r26", "r25", "r24", "r23", "r22", "r21", "r20", "r28", "r31", "memory"
63 #define ASM_EAGAIN -EAGAIN
66 /* The only basic operation needed is compare and exchange. */
67 # define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
69 volatile int lws_errno = EFAULT; \
70 volatile int lws_ret = 0xdeadbeef; \
73 "copy %3, %%r26 \n\t" \
74 "copy %4, %%r25 \n\t" \
75 "copy %5, %%r24 \n\t" \
76 "ble " LWS "(%%sr2, %%r0) \n\t" \
78 "cmpib,=,n " ASM_EAGAIN ",%%r21,0 \n\t" \
80 "stw %%r28, %0 \n\t" \
81 "sub %%r0, %%r21, %%r21 \n\t" \
82 "stw %%r21, %1 \n\t" \
83 : "=m" (lws_ret), "=m" (lws_errno), "=m" (*mem) \
84 : "r" (mem), "r" (oldval), "r" (newval) \
88 if(lws_errno == EFAULT || lws_errno == ENOSYS) \
94 # define atomic_compare_and_exchange_bool_acq(mem, newval, oldval) \
97 ret = atomic_compare_and_exchange_val_acq(mem, newval, oldval); \
98 /* Return 1 if it was already acquired */ \
102 /* Non-atomic primitives. */
103 # define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
104 ({ __typeof (mem) __gmemp = (mem); \
105 __typeof (*mem) __gret = *__gmemp; \
106 __typeof (*mem) __gnewval = (newval); \
108 if (__gret == (oldval)) \
109 *__gmemp = __gnewval; \
112 # define atomic_compare_and_exchange_bool_acq(mem, newval, oldval) \
113 ({ __typeof (mem) __gmemp = (mem); \
114 __typeof (*mem) __gnewval = (newval); \
116 *__gmemp == (oldval) ? (*__gmemp = __gnewval, 0) : 1; })
119 #endif /* bits/atomic.h */