From 6541ccfdd0713242fc544075984d77bfeb9adc46 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Wed, 6 Mar 2024 17:16:50 -0800 Subject: [PATCH] Add test_bit to utils bitmap Add test_bit() to the trivial utils bitmap.c implementation. Signed-off-by: Zach Brown --- utils/src/bitmap.c | 5 +++++ utils/src/bitmap.h | 1 + 2 files changed, 6 insertions(+) diff --git a/utils/src/bitmap.c b/utils/src/bitmap.c index 5e9ab615..c295b21a 100644 --- a/utils/src/bitmap.c +++ b/utils/src/bitmap.c @@ -10,6 +10,11 @@ * Just a quick simple native bitmap. */ +int test_bit(unsigned long *bits, u64 nr) +{ + return !!(bits[nr / BITS_PER_LONG] & (1UL << (nr & (BITS_PER_LONG - 1)))); +} + void set_bit(unsigned long *bits, u64 nr) { bits[nr / BITS_PER_LONG] |= 1UL << (nr & (BITS_PER_LONG - 1)); diff --git a/utils/src/bitmap.h b/utils/src/bitmap.h index 993bad4e..7b3ef927 100644 --- a/utils/src/bitmap.h +++ b/utils/src/bitmap.h @@ -1,6 +1,7 @@ #ifndef _BITMAP_H_ #define _BITMAP_H_ +int test_bit(unsigned long *bits, u64 nr); void set_bit(unsigned long *bits, u64 nr); void clear_bit(unsigned long *bits, u64 nr); u64 find_next_set_bit(unsigned long *start, u64 from, u64 total);