On 04/25/2018 01:45 PM, Michael Clark wrote:
> + uint32_t old, new;
> + do {
> + old = atomic_read(&plic->pending[word]);
> + new = (old & ~(1 << (irq & 31))) | (-!!pending & (1 << (irq & 31)));
> + } while (atomic_cmpxchg(&plic->pending[word], old, new) != old);
I prefer
uint32_t old, new, cmp = atomic_read(...);
do {
old = cmp;
new = ...;
cmp = atomic_cmpxchg(...);
} while (old != cmp);
to avoid an extra load, should we loop.
That said, what you have is not wrong. So,
Reviewed-by: Richard Henderson <[email protected]>
r~