Thread (24 messages) 24 messages, 6 authors, 2017-10-12

Re: [PATCH 1/4] bitops: Introduce assign_bit()

From: Linus Walleij <hidden>
Date: 2017-08-23 07:32:29

On Mon, Aug 21, 2017 at 3:12 PM, Lukas Wunner [off-list ref] wrote:
A common idiom is to assign a value to a bit with:

    if (value)
        set_bit(nr, addr);
    else
        clear_bit(nr, addr);

Likewise common is the one-line expression variant:

    value ? set_bit(nr, addr) : clear_bit(nr, addr);

Commit 9a8ac3ae682e ("dm mpath: cleanup QUEUE_IF_NO_PATH bit
manipulation by introducing assign_bit()") introduced assign_bit()
to the md subsystem for brevity.

Make it available to others, in particular gpiolib and the upcoming
driver for Maxim MAX3191x industrial serializer chips.

Cc: Bart Van Assche <redacted>
Cc: Alasdair Kergon <agk@redhat.com>
Cc: Mike Snitzer <redacted>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Looks reasonable.
+static __always_inline void assign_bit(bool value, long nr,
+                                      volatile unsigned long *addr)
+{
+       if (value)
+               set_bit(nr, addr);
+       else
+               clear_bit(nr, addr);
+}
+
+static __always_inline void __assign_bit(bool value, long nr,
+                                        volatile unsigned long *addr)
+{
+       if (value)
+               __set_bit(nr, addr);
+       else
+               __clear_bit(nr, addr);
+}
What I have never understood is the semantic difference between
bitop_foo() and __bitop_foo().

And I even use them quite a lot.

Can someone explain when I use the bitop_foo() and when I
use the __bitop_foo(). I am asking so I can understand patch
2/4 in this series.

I guess this is why I generally detest the __annotation, since it is
so unspecific and unclear, but that is not something I expect you
to solve in this patch.

Yours,
Linus Walleij
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help