On 13/03/2015 09:32, Paolo Bonzini wrote: > > > On 13/03/2015 09:16, Fam Zheng wrote: >>>>>> + if (atomic_cmpxchg(&bounce.in_use, false, true)) { >>>> >>>> atomic_or is enough... >> atomic_cmpxchg is here to take the ownership of bounce iff it is not in use, >> so >> I think it is necessary. > > It's changing false to true and true to true, so you can do > > if (atomic_or(&bounce.in_use, 1)) { > // was true already > }
... and actually, atomic_xchg is even better (on x86, atomic_or is compiled into a cmpxchg loop, but atomic_xchg is a single instruction). Paolo