Re: [PATCH] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()'
From: Linus Torvalds
Date: Tue Mar 15 2016 - 12:18:54 EST
On Tue, Mar 15, 2016 at 2:32 AM, Ingo Molnar <mingo@xxxxxxxxxx> wrote:
>
> I can see two other problems with it as well:
>
> 1) 'ptr' may get evaluated multiple times as well, not just 'mask'.
Right you are.
> 2) its naming sucks. "fetch_or()" does not really signal that it's a
> fundamentally atomic operation, nor what API family it belongs to.
Actually, I like the naming, I just don't like the implementation.
It's not just the "evaluated multiple times", it's also the fact that
if we start doing "fetch_or()", then some day we'll want "fetch_and()"
or "fetch_clear()" etc.
Or, in fact, "fetch_add()", which is often closer to what hardware
does than the "atomic_add_return()" we have now (the difference is
that "fetch_add()" returns the original value, while
"atomic_add_return()" returns the end result).
So what I meant with "try to match what we already have in our
existing atomic.h" is that we do the _infrastructure_ so well. We do
it well both by having separate UP and SMP versions of the underlying
helpers, but we do it well by having those helpers that are then used
to implement the different atomic versions.
So I'd like something similar for the "fetch_op" thing.
Linus