Re: [PATCH 4/5] atomic: Introduce atomic_try_cmpxchg()

2017-02-06 Thread Peter Zijlstra
On Mon, Feb 06, 2017 at 12:24:28PM +0800, Boqun Feng wrote: > On Fri, Feb 03, 2017 at 02:26:02PM +0100, Peter Zijlstra wrote: > > > > for (;;) { > > new = val $op $imm; > > if (try_cmpxchg(ptr, &val, new)) > > break; > > } > > > > while also ge

Re: [PATCH 4/5] atomic: Introduce atomic_try_cmpxchg()

2017-02-05 Thread Boqun Feng
On Mon, Feb 06, 2017 at 12:24:28PM +0800, Boqun Feng wrote: > On Fri, Feb 03, 2017 at 02:26:02PM +0100, Peter Zijlstra wrote: > > Add a new cmpxchg interface: > > > > bool try_cmpxchg(u{8,16,32,64} *ptr, u{8,16,32,64} *val, u{8,16,32,64} > > new); > > > > Where the boolean returns the result o

Re: [PATCH 4/5] atomic: Introduce atomic_try_cmpxchg()

2017-02-05 Thread Boqun Feng
On Fri, Feb 03, 2017 at 02:26:02PM +0100, Peter Zijlstra wrote: > Add a new cmpxchg interface: > > bool try_cmpxchg(u{8,16,32,64} *ptr, u{8,16,32,64} *val, u{8,16,32,64} new); > > Where the boolean returns the result of the compare; and thus if the > exchange happened; and in case of failure, t

[PATCH 4/5] atomic: Introduce atomic_try_cmpxchg()

2017-02-03 Thread Peter Zijlstra
Add a new cmpxchg interface: bool try_cmpxchg(u{8,16,32,64} *ptr, u{8,16,32,64} *val, u{8,16,32,64} new); Where the boolean returns the result of the compare; and thus if the exchange happened; and in case of failure, the new value of *ptr is returned in *val. This allows simplification/improv