Changes in kernel/generic/include/adt/bitmap.h [9d58539:7de18418] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/adt/bitmap.h
r9d58539 r7de18418 38 38 #include <typedefs.h> 39 39 40 #define BITS2BYTES(bits) (bits ? ((((bits)-1)>>3)+1) : 0) 40 #define BITMAP_ELEMENT 8 41 #define BITMAP_REMAINER 7 41 42 42 43 typedef struct { 43 uint8_t *map; 44 size_t bits; 44 size_t elements; 45 uint8_t *bits; 46 47 size_t block_size; 48 uint8_t *blocks; 45 49 } bitmap_t; 46 50 47 extern void bitmap_initialize(bitmap_t *bitmap, uint8_t *map, size_t bits); 48 extern void bitmap_set_range(bitmap_t *bitmap, size_t start, size_t bits); 49 extern void bitmap_clear_range(bitmap_t *bitmap, size_t start, size_t bits); 50 extern void bitmap_copy(bitmap_t *dst, bitmap_t *src, size_t bits); 51 static inline void bitmap_set(bitmap_t *bitmap, size_t element, 52 unsigned int value) 53 { 54 if (element < bitmap->elements) { 55 /* 56 * The 2nd level bitmap is conservative. 57 * Make sure we update it properly. 58 */ 59 60 if (value) { 61 bitmap->bits[element / BITMAP_ELEMENT] |= 62 (1 << (element & BITMAP_REMAINER)); 63 } else { 64 bitmap->bits[element / BITMAP_ELEMENT] &= 65 ~(1 << (element & BITMAP_REMAINER)); 66 67 if (bitmap->block_size > 0) { 68 size_t block = element / bitmap->block_size; 69 70 bitmap->blocks[block / BITMAP_ELEMENT] &= 71 ~(1 << (block & BITMAP_REMAINER)); 72 } 73 } 74 } 75 } 51 76 52 static inline int bitmap_get(bitmap_t *bitmap, size_t bit)77 static inline unsigned int bitmap_get(bitmap_t *bitmap, size_t element) 53 78 { 54 if (bit >= bitmap->bits)79 if (element >= bitmap->elements) 55 80 return 0; 56 81 57 return !! ((bitmap->map)[bit/8] & (1 << (bit & 7))); 82 return !!((bitmap->bits)[element / BITMAP_ELEMENT] & 83 (1 << (element & BITMAP_REMAINER))); 58 84 } 59 85 86 extern size_t bitmap_size(size_t, size_t); 87 extern void bitmap_initialize(bitmap_t *, size_t, size_t, void *); 88 89 extern void bitmap_set_range(bitmap_t *, size_t, size_t); 90 extern void bitmap_clear_range(bitmap_t *, size_t, size_t); 91 92 extern int bitmap_find_range(bitmap_t *, size_t, size_t, size_t); 93 extern int bitmap_allocate_range(bitmap_t *, size_t, size_t, size_t, size_t *); 94 extern void bitmap_free_range(bitmap_t *, size_t, size_t); 95 extern void bitmap_copy(bitmap_t *, bitmap_t *, size_t); 60 96 61 97 #endif
Note:
See TracChangeset
for help on using the changeset viewer.