Re: [PATCH] asm-generic/atomic: Add try_cmpxchg() fallbacks

Peter Zijlstra
2020-02-18T14:40:49Z

On Tue, Feb 18, 2020 at 03:27:00PM +0100, Peter Zijlstra wrote:
> diff --git a/scripts/atomic/gen-atomic-fallback.sh b/scripts/atomic/gen-atomic-fallback.sh
> index b6c6f5d306a7..3c9be8d550e0 100755
> --- a/scripts/atomic/gen-atomic-fallback.sh
> +++ b/scripts/atomic/gen-atomic-fallback.sh
> @@ -140,6 +140,32 @@ cat <<EOF
> EOF
> }
>
> +gen_try_cmpxchg_fallback()
> +{
> + local order="$1"; shift;
> +
> +cat <<EOF
> +#ifndef try_cmpxchg${order}
> +#define try_cmpxchg${order}(_ptr, _oldp, _new) \\
> +({ \\
> + typeof(*ptr) ___r, ___o = *(_oldp); \\
*(_ptr)
> + ___r = cmpxchg${order}((_ptr), ___o, (_new)); \\
> + if (unlikely(___r != ___o)) \\
> + *(_old) = ___r; \\
*(_oldp)
> + likely(___r == ___o); \\
> +})
> +#endif /* try_cmpxchg${order} */

And it actually builds, as tested on an ARM build.