summaryrefslogtreecommitdiff
path: root/scripts/atomic/fallbacks/inc_unless_negative
blob: e70d9fdfc3d64b2119f7807ae801695d2352e5ab (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
if /bin/sh ${ATOMICDIR}/chkdup.sh arch_${atomic}_inc_unless_negative inc_unless_negative
then
cat <<EOF
/**
 * arch_${atomic}_inc_unless_negative - Atomic increment if old value is non-negative
 * @v: pointer of type ${atomic}_t
 *
 * Atomically increment @v with full ordering, but only if the original
 * value is greater than or equal to zero.  Return @true if the increment
 * happened and @false otherwise.
 */
EOF
fi
cat <<EOF
static __always_inline bool
arch_${atomic}_inc_unless_negative(${atomic}_t *v)
{
	${int} c = arch_${atomic}_read(v);

	do {
		if (unlikely(c < 0))
			return false;
	} while (!arch_${atomic}_try_cmpxchg(v, &c, c + 1));

	return true;
}
EOF