Messages in this thread Patch in this message | | | From | Will Deacon <> | Subject | [PATCH] bitops: Move test_bit() into bitops/atomic.h | Date | Thu, 21 May 2020 15:31:29 +0100 |
| |
test_bit() is an atomic operation as documented by atomic_bitops.txt. Move the function from bitops/non-atomic.h to bitops/atomic.h and adjust its implementation to align with the other atomic bitops.
Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Will Deacon <will@kernel.org> --- include/asm-generic/bitops/atomic.h | 6 ++++++ include/asm-generic/bitops/non-atomic.h | 10 ---------- 2 files changed, 6 insertions(+), 10 deletions(-)
Just found this kicking around on a branch from last year!
diff --git a/include/asm-generic/bitops/atomic.h b/include/asm-generic/bitops/atomic.h index dd90c9792909..5fc4399d8fb4 100644 --- a/include/asm-generic/bitops/atomic.h +++ b/include/asm-generic/bitops/atomic.h @@ -17,6 +17,12 @@ static inline void set_bit(unsigned int nr, volatile unsigned long *p) atomic_long_or(BIT_MASK(nr), (atomic_long_t *)p); } +static inline int test_bit(unsigned int nr, const volatile unsigned long *p) +{ + p += BIT_WORD(nr); + return !!(READ_ONCE(*p) & BIT_MASK(nr)); +} + static inline void clear_bit(unsigned int nr, volatile unsigned long *p) { p += BIT_WORD(nr); diff --git a/include/asm-generic/bitops/non-atomic.h b/include/asm-generic/bitops/non-atomic.h index 7e10c4b50c5d..8b44da59a9d0 100644 --- a/include/asm-generic/bitops/non-atomic.h +++ b/include/asm-generic/bitops/non-atomic.h @@ -96,14 +96,4 @@ static inline int __test_and_change_bit(int nr, return (old & mask) != 0; } -/** - * test_bit - Determine whether a bit is set - * @nr: bit number to test - * @addr: Address to start counting from - */ -static inline int test_bit(int nr, const volatile unsigned long *addr) -{ - return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); -} - #endif /* _ASM_GENERIC_BITOPS_NON_ATOMIC_H_ */ -- 2.26.2.761.g0e0b3e54be-goog
| |