diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 9f47ec2b..a7231b8b 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -25,6 +25,17 @@ int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, #define small_const_nbits(nbits) \ (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) +static inline void bitmap_complement(unsigned long *dst, const unsigned long *src, + unsigned int bits) +{ + unsigned int k, lim = bits/BITS_PER_LONG; + for (k = 0; k < lim; ++k) + dst[k] = ~src[k]; + + if (bits % BITS_PER_LONG) + dst[k] = ~src[k]; +} + static inline void bitmap_zero(unsigned long *dst, int nbits) { memset(dst, 0, BITS_TO_LONGS(nbits) * sizeof(unsigned long)); diff --git a/include/linux/bug.h b/include/linux/bug.h index aa5776c7..89cdd30d 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -15,7 +15,7 @@ #define BUG_ON(cond) assert(!(cond)) #define WARN_ON_ONCE(cond) assert(!(cond)) -#define WARN_ONCE(cond, msg) assert(!(cond)) +#define WARN_ONCE(cond, msg) ({ bool _r = (cond); if (_r) assert(0); _r; }) #define __WARN() assert(0) #define __WARN_printf(arg...) assert(0) diff --git a/include/linux/closure.h b/include/linux/closure.h index 33280d30..a9de6d93 100644 --- a/include/linux/closure.h +++ b/include/linux/closure.h @@ -382,4 +382,26 @@ static inline void closure_call(struct closure *cl, closure_fn fn, continue_at_nobarrier(cl, fn, wq); } +#define __closure_wait_event(waitlist, _cond) \ +do { \ + struct closure cl; \ + \ + closure_init_stack(&cl); \ + \ + while (1) { \ + closure_wait(waitlist, &cl); \ + if (_cond) \ + break; \ + closure_sync(&cl); \ + } \ + closure_wake_up(waitlist); \ + closure_sync(&cl); \ +} while (0) + +#define closure_wait_event(waitlist, _cond) \ +do { \ + if (!(_cond)) \ + __closure_wait_event(waitlist, _cond); \ +} while (0) + #endif /* _LINUX_CLOSURE_H */ diff --git a/include/linux/random.h b/include/linux/random.h index 95a15d05..6d63e045 100644 --- a/include/linux/random.h +++ b/include/linux/random.h @@ -37,4 +37,12 @@ static inline int get_random_int(void) return v; } +static inline long get_random_long(void) +{ + long v; + + get_random_bytes(&v, sizeof(v)); + return v; +} + #endif /* _LINUX_RANDOM_H */