[PATCH 1/3] erofs-utils: lib: add bitops header
Gao Xiang
hsiangkao at linux.alibaba.com
Fri Jul 19 18:13:12 AEST 2024
On 2024/7/18 13:40, Hongzhen Luo wrote:
> Add bitops header for subsequent bloom filter implementation.
> This is borrowed from a part of the previous patch. See:
> https://lore.kernel.org/all/20230802091750.74181-3-jefflexu@linux.alibaba.com/.
>
> Signed-off-by: Hongzhen Luo <hongzhen at linux.alibaba.com>
> ---
> include/erofs/bitops.h | 42 ++++++++++++++++++++++++++++++++++++++++++
> lib/Makefile.am | 1 +
> 2 files changed, 43 insertions(+)
> create mode 100644 include/erofs/bitops.h
>
> diff --git a/include/erofs/bitops.h b/include/erofs/bitops.h
> new file mode 100644
> index 0000000..ef60d6e
> --- /dev/null
> +++ b/include/erofs/bitops.h
> @@ -0,0 +1,42 @@
> +/* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */
> +#ifndef __EROFS_BITOPS_H
> +#define __EROFS_BITOPS_H
> +
> +#ifdef __cplusplus
> +extern "C"
> +{
> +#endif
> +
> +#include "defs.h"
> +
> +struct bitmap {
> + unsigned long size; /* size of bitmap in bits */
> + unsigned long *map;
> +};
What is the meaning of this structure, please just fold it into
the original structure.
> +
> +static inline void set_bit(int nr, volatile unsigned long *addr)
Since it's not atomic, please use __set_bit instead.
> +{
> + unsigned long mask = BIT_MASK(nr);
> + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
> +
> + *p |= mask;
> +}
> +
> +static inline void clear_bit(int nr, volatile unsigned long *addr)
please use __clear_bit instead.
> +{
> + unsigned long mask = BIT_MASK(nr);
> + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
> +
> + *p &= ~mask;
> +}
> +
> +static inline int test_bit(int nr, const volatile unsigned long *addr)
please call it __test_bit instead, or use READ_ONCE to wrap it up.
Thanks,
Gao Xiang
More information about the Linux-erofs
mailing list