Re: locking/atomic: Introduce atomic_try_cmpxchg()
From: Peter Zijlstra
Date: Fri Mar 24 2017 - 14:05:15 EST
On Fri, Mar 24, 2017 at 07:00:25PM +0100, Peter Zijlstra wrote:
> static inline bool try_cmpxchg2(unsigned int *ptr, unsigned int *val, unsigned int new)
> {
> unsigned int old = *val;
> bool success;
>
> asm volatile goto("lock cmpxchgl %[new], %[ptr]; "
> "jnz %[label]"
> : /* no output */
> : [ptr] "+m" (*ptr),
> [old] "+a" (old)
> [new] "r" (new)
> : "memory"
> : label);
> return 1;
>
> label:
> *val = old;
> return 0;
> }
N/m, I'm apparently so tired I didn't see the compiler errors :/