0001 cat << EOF
0002 /**
0003 * arch_${atomic}_fetch_add_unless - add unless the number is already a given value
0004 * @v: pointer of type ${atomic}_t
0005 * @a: the amount to add to v...
0006 * @u: ...unless v is equal to u.
0007 *
0008 * Atomically adds @a to @v, so long as @v was not already @u.
0009 * Returns original value of @v
0010 */
0011 static __always_inline ${int}
0012 arch_${atomic}_fetch_add_unless(${atomic}_t *v, ${int} a, ${int} u)
0013 {
0014 ${int} c = arch_${atomic}_read(v);
0015
0016 do {
0017 if (unlikely(c == u))
0018 break;
0019 } while (!arch_${atomic}_try_cmpxchg(v, &c, c + a));
0020
0021 return c;
0022 }
0023 EOF