]>
git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/blob - arch/sh/include/asm/atomic.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_SH_ATOMIC_H
3 #define __ASM_SH_ATOMIC_H
5 #if defined(CONFIG_CPU_J2)
7 #include <asm-generic/atomic.h>
12 * Atomic operations that C can't guarantee us. Useful for
13 * resource counting etc..
17 #include <linux/compiler.h>
18 #include <linux/types.h>
19 #include <asm/cmpxchg.h>
20 #include <asm/barrier.h>
22 #define ATOMIC_INIT(i) { (i) }
24 #define atomic_read(v) READ_ONCE((v)->counter)
25 #define atomic_set(v,i) WRITE_ONCE((v)->counter, (i))
27 #if defined(CONFIG_GUSA_RB)
28 #include <asm/atomic-grb.h>
29 #elif defined(CONFIG_CPU_SH4A)
30 #include <asm/atomic-llsc.h>
32 #include <asm/atomic-irq.h>
35 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
36 #define atomic_dec_return(v) atomic_sub_return(1, (v))
37 #define atomic_inc_return(v) atomic_add_return(1, (v))
38 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
39 #define atomic_sub_and_test(i,v) (atomic_sub_return((i), (v)) == 0)
40 #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
42 #define atomic_inc(v) atomic_add(1, (v))
43 #define atomic_dec(v) atomic_sub(1, (v))
45 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
46 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
49 * __atomic_add_unless - add unless the number is a given value
50 * @v: pointer of type atomic_t
51 * @a: the amount to add to v...
52 * @u: ...unless v is equal to u.
54 * Atomically adds @a to @v, so long as it was not @u.
55 * Returns the old value of @v.
57 static inline int __atomic_add_unless(atomic_t
*v
, int a
, int u
)
62 if (unlikely(c
== (u
)))
64 old
= atomic_cmpxchg((v
), c
, c
+ (a
));
73 #endif /* CONFIG_CPU_J2 */
75 #endif /* __ASM_SH_ATOMIC_H */