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