xref: /OK3568_Linux_fs/kernel/scripts/atomic/fallbacks/fetch_add_unless (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyuncat << EOF
2*4882a593Smuzhiyun/**
3*4882a593Smuzhiyun * ${arch}${atomic}_fetch_add_unless - add unless the number is already a given value
4*4882a593Smuzhiyun * @v: pointer of type ${atomic}_t
5*4882a593Smuzhiyun * @a: the amount to add to v...
6*4882a593Smuzhiyun * @u: ...unless v is equal to u.
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * Atomically adds @a to @v, so long as @v was not already @u.
9*4882a593Smuzhiyun * Returns original value of @v
10*4882a593Smuzhiyun */
11*4882a593Smuzhiyunstatic __always_inline ${int}
12*4882a593Smuzhiyun${arch}${atomic}_fetch_add_unless(${atomic}_t *v, ${int} a, ${int} u)
13*4882a593Smuzhiyun{
14*4882a593Smuzhiyun	${int} c = ${arch}${atomic}_read(v);
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun	do {
17*4882a593Smuzhiyun		if (unlikely(c == u))
18*4882a593Smuzhiyun			break;
19*4882a593Smuzhiyun	} while (!${arch}${atomic}_try_cmpxchg(v, &c, c + a));
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun	return c;
22*4882a593Smuzhiyun}
23*4882a593SmuzhiyunEOF
24