From e5032709b29eb42568c3937a533898728a15efa1 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Mon, 10 Jun 2013 13:37:14 +0200 Subject: utils: add bitfield inline ops Signed-off-by: Felix Fietkau --- utils.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'utils.h') diff --git a/utils.h b/utils.h index 71a4692..db6217e 100644 --- a/utils.h +++ b/utils.h @@ -22,6 +22,7 @@ #include #include #include +#include #include /* @@ -151,4 +152,18 @@ void clock_gettime(int type, struct timespec *tv); #define __packed __attribute__((packed)) #endif +#ifndef BITS_PER_LONG +#define BITS_PER_LONG (8 * sizeof(unsigned long)) +#endif + +static inline void bitfield_set(unsigned long *bits, int bit) +{ + bits[bit / BITS_PER_LONG] |= (1UL << (bit % BITS_PER_LONG)); +} + +static inline bool bitfield_test(unsigned long *bits, int bit) +{ + return !!(bits[bit / BITS_PER_LONG] & (1UL << (bit % BITS_PER_LONG))); +} + #endif -- cgit v1.2.3