Staging
v0.8.1
https://github.com/torvalds/linux
Raw File
Tip revision: 88084a3df1672e131ddc1b4e39eeacfd39864acf authored by Linus Torvalds on 03 July 2022, 22:39:28 UTC
Linux 5.19-rc5
Tip revision: 88084a3
fetch_add_unless
cat << EOF
/**
 * arch_${atomic}_fetch_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 original value of @v
 */
static __always_inline ${int}
arch_${atomic}_fetch_add_unless(${atomic}_t *v, ${int} a, ${int} u)
{
	${int} c = arch_${atomic}_read(v);

	do {
		if (unlikely(c == u))
			break;
	} while (!arch_${atomic}_try_cmpxchg(v, &c, c + a));

	return c;
}
EOF
back to top