blob: 88c8372109f8d2454d44b0f82d05a479da0033f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#include <linux/module.h>
#include <asm/atomic.h>
/**
* __arch_atomic_add_unless - add unless the number is already a given value
* @v: pointer of type atomic_t
* @a: the amount to add to v...
* @u: ...unless v is equal to u.
*
* Atomically adds @a to @v, so long as @v was not already @u.
* Returns the old value of @v.
*/
int __arch_atomic_add_unless(atomic_t *v, int a, int u)
{
int c, old;
c = arch_atomic_read(v);
for (;;) {
if (unlikely(c == (u)))
break;
old = arch_atomic_cmpxchg((v), c, c + (a));
if (likely(old == c))
break;
c = old;
}
return c;
}
EXPORT_SYMBOL(__arch_atomic_add_unless);
|