blob: 77f0fa1eeeb13f6b096136796f79c74ada5f08f5 (
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
28
|
if /bin/sh ${ATOMICDIR}/chkdup.sh arch_${atomic}_try_cmpxchg${order} try_cmpxchg
then
cat <<EOF
/**
* arch_${atomic}_try_cmpxchg${order} - Atomic cmpxchg with bool return value
* @v: pointer of type ${atomic}_t
* @old: desired old value to match
* @new: new value to put in
*
* Atomically compares @new to *@v, and if equal, stores @new to *@v,
* providing ${docbook_order} ordering.
* Returns @true if the cmpxchg operation succeeded, and @false otherwise.
* On failure, stores the original value of *@v into *@old, which permits
* a retry without a reload from *@v.
*/
EOF
fi
cat <<EOF
static __always_inline bool
arch_${atomic}_try_cmpxchg${order}(${atomic}_t *v, ${int} *old, ${int} new)
{
${int} r, o = *old;
r = arch_${atomic}_cmpxchg${order}(v, o, new);
if (unlikely(r != o))
*old = r;
return likely(r == o);
}
EOF
|