2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
17 #ifndef _ASM_TILE_ATOMIC_H
18 #define _ASM_TILE_ATOMIC_H
20 #include <asm/cmpxchg.h>
24 #include <linux/compiler.h>
25 #include <linux/types.h>
27 #define ATOMIC_INIT(i) { (i) }
30 * atomic_read - read atomic variable
31 * @v: pointer of type atomic_t
33 * Atomically reads the value of @v.
35 static inline int atomic_read(const atomic_t *v)
37 return ACCESS_ONCE(v->counter);
41 * atomic_sub_return - subtract integer and return
42 * @v: pointer of type atomic_t
43 * @i: integer value to subtract
45 * Atomically subtracts @i from @v and returns @v - @i
47 #define atomic_sub_return(i, v) atomic_add_return((int)(-(i)), (v))
50 * atomic_sub - subtract integer from atomic variable
51 * @i: integer value to subtract
52 * @v: pointer of type atomic_t
54 * Atomically subtracts @i from @v.
56 #define atomic_sub(i, v) atomic_add((int)(-(i)), (v))
59 * atomic_sub_and_test - subtract value from variable and test result
60 * @i: integer value to subtract
61 * @v: pointer of type atomic_t
63 * Atomically subtracts @i from @v and returns true if the result is
64 * zero, or false for all other cases.
66 #define atomic_sub_and_test(i, v) (atomic_sub_return((i), (v)) == 0)
69 * atomic_inc_return - increment memory and return
70 * @v: pointer of type atomic_t
72 * Atomically increments @v by 1 and returns the new value.
74 #define atomic_inc_return(v) atomic_add_return(1, (v))
77 * atomic_dec_return - decrement memory and return
78 * @v: pointer of type atomic_t
80 * Atomically decrements @v by 1 and returns the new value.
82 #define atomic_dec_return(v) atomic_sub_return(1, (v))
85 * atomic_inc - increment atomic variable
86 * @v: pointer of type atomic_t
88 * Atomically increments @v by 1.
90 #define atomic_inc(v) atomic_add(1, (v))
93 * atomic_dec - decrement atomic variable
94 * @v: pointer of type atomic_t
96 * Atomically decrements @v by 1.
98 #define atomic_dec(v) atomic_sub(1, (v))
101 * atomic_dec_and_test - decrement and test
102 * @v: pointer of type atomic_t
104 * Atomically decrements @v by 1 and returns true if the result is 0.
106 #define atomic_dec_and_test(v) (atomic_dec_return(v) == 0)
109 * atomic_inc_and_test - increment and test
110 * @v: pointer of type atomic_t
112 * Atomically increments @v by 1 and returns true if the result is 0.
114 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
117 * atomic_add_negative - add and test if negative
118 * @v: pointer of type atomic_t
119 * @i: integer value to add
121 * Atomically adds @i to @v and returns true if the result is
122 * negative, or false when result is greater than or equal to zero.
124 #define atomic_add_negative(i, v) (atomic_add_return((i), (v)) < 0)
126 #endif /* __ASSEMBLY__ */
129 #include <asm/atomic_32.h>
131 #include <asm/atomic_64.h>
134 #endif /* _ASM_TILE_ATOMIC_H */