Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1717216
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 1/4] bitops: Introduce assign_bit() |
| Date | 2017-08-22 11:30 +0200 |
| Message-ID | <uhdFw-ng-15@gated-at.bofh.it> (permalink) |
| References | <uhcT7-8f0-5@gated-at.bofh.it> <uhcT7-8f0-7@gated-at.bofh.it> <uhcT7-8f0-9@gated-at.bofh.it> <uhcT7-8f0-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Tue, Aug 22, 2017 at 10:30:50AM +0200, Lukas Wunner wrote:
> diff --git a/include/linux/bitops.h b/include/linux/bitops.h
> index a83c822c35c2..097af36887c0 100644
> --- a/include/linux/bitops.h
> +++ b/include/linux/bitops.h
> @@ -226,6 +226,30 @@ static inline unsigned long __ffs64(u64 word)
> return __ffs((unsigned long)word);
> }
>
> +/**
> + * assign_bit - Assign value to a bit in memory
> + * @value: the value to assign
> + * @nr: the bit to set
> + * @addr: the address to start counting from
> + */
> +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);
> +}
> +
I dislike the argument order, in C you naturally write: dst = src. So I
would have expected:
assign_bit(nr, addr, val);
but we have quite a few of these backwards functions in the kernel (like
most of the atomic_t family) and I didn't check to see if the existing
bitops are part of that 'tradition'.
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: [PATCH 1/4] bitops: Introduce assign_bit() Lukas Wunner <lukas@wunner.de> - 2017-08-22 10:40 +0200
Re: [PATCH 1/4] bitops: Introduce assign_bit() Peter Zijlstra <peterz@infradead.org> - 2017-08-22 11:30 +0200
Re: [PATCH 1/4] bitops: Introduce assign_bit() Lukas Wunner <lukas@wunner.de> - 2017-08-22 12:10 +0200
csiph-web