Debian Codegraph @

utils/keytable/bpf_protocols/bitmap.h

raw
1
2 #ifndef __BITMAP_H__
3 #define __BITMAP_H__
4
5 #define BITS_PER_LONG 64
6 #define BITS_TO_LONG(n) \
7 (((n) + BITS_PER_LONG - 1) / BITS_PER_LONG)
8
9
10 #define DECLARE_BITMAP(name, bits) \
11 unsigned long name[BITS_TO_LONG(bits)]
12
13 static void inline bitmap_zero(unsigned long *bitmap, int bits)
14 {
15 for (int i = 0; i < BITS_TO_LONG(bits); i++)
16 bitmap[i] = 0;
17 }
18
19 static void inline bitmap_fill(unsigned long *bitmap, int bits)
20 {
21 for (int i = 0; i < BITS_TO_LONG(bits); i++)
22 bitmap[i] = ~0;
23 }
24
25 #define bitmap_set(b, n) \
26 b[n / BITS_PER_LONG] |= 1 << (n % BITS_PER_LONG)
27
28 #define bitmap_clear(b, n) \
29 b[n / BITS_PER_LONG] &= ~(1 << (n % BITS_PER_LONG))
30
31 #define bitmap_test(b, n) \
32 (b[n / BITS_PER_LONG] & (1 << (n % BITS_PER_LONG))) != 0
33
34 #endif