2018-09-04 11:48:25 +01:00
|
|
|
cat << EOF
|
|
|
|
|
/**
|
2021-07-13 11:52:50 +01:00
|
|
|
* arch_${atomic}_fetch_add_unless - add unless the number is already a given value
|
2018-09-04 11:48:25 +01:00
|
|
|
* @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 original value of @v
|
|
|
|
|
*/
|
2019-11-26 15:04:05 +01:00
|
|
|
static __always_inline ${int}
|
2021-07-13 11:52:50 +01:00
|
|
|
arch_${atomic}_fetch_add_unless(${atomic}_t *v, ${int} a, ${int} u)
|
2018-09-04 11:48:25 +01:00
|
|
|
{
|
2021-07-13 11:52:50 +01:00
|
|
|
${int} c = arch_${atomic}_read(v);
|
2018-09-04 11:48:25 +01:00
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
if (unlikely(c == u))
|
|
|
|
|
break;
|
2021-07-13 11:52:50 +01:00
|
|
|
} while (!arch_${atomic}_try_cmpxchg(v, &c, c + a));
|
2018-09-04 11:48:25 +01:00
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
EOF
|