Linux 4.16-rc2
[linux-2.6-block.git] / arch / metag / include / asm / atomic.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
6006c0d8
JH
2#ifndef __ASM_METAG_ATOMIC_H
3#define __ASM_METAG_ATOMIC_H
4
5#include <linux/compiler.h>
6#include <linux/types.h>
7#include <asm/cmpxchg.h>
40074dec 8#include <asm/barrier.h>
6006c0d8
JH
9
10#if defined(CONFIG_METAG_ATOMICITY_IRQSOFF)
11/* The simple UP case. */
12#include <asm-generic/atomic.h>
13#else
14
15#if defined(CONFIG_METAG_ATOMICITY_LOCK1)
16#include <asm/atomic_lock1.h>
17#else
18#include <asm/atomic_lnkget.h>
19#endif
20
21#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
22
23#define atomic_dec_return(v) atomic_sub_return(1, (v))
24#define atomic_inc_return(v) atomic_add_return(1, (v))
25
26/*
27 * atomic_inc_and_test - increment and test
28 * @v: pointer of type atomic_t
29 *
30 * Atomically increments @v by 1
31 * and returns true if the result is zero, or false for all
32 * other cases.
33 */
34#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
35
36#define atomic_sub_and_test(i, v) (atomic_sub_return((i), (v)) == 0)
37#define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
38
39#define atomic_inc(v) atomic_add(1, (v))
40#define atomic_dec(v) atomic_sub(1, (v))
41
42#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
35d04077 43#define atomic_dec_if_positive(v) atomic_sub_if_positive(1, v)
6006c0d8 44
6006c0d8
JH
45#endif
46
6006c0d8
JH
47#include <asm-generic/atomic64.h>
48
49#endif /* __ASM_METAG_ATOMIC_H */