00001 #ifndef _GPXE_BITMAP_H 00002 #define _GPXE_BITMAP_H 00003 00004 /** @file 00005 * 00006 * Bitmaps for multicast downloads 00007 * 00008 */ 00009 00010 FILE_LICENCE ( GPL2_OR_LATER ); 00011 00012 #include <stdint.h> 00013 #include <stddef.h> 00014 #include <stdlib.h> 00015 00016 /** A single block of bits within a bitmap */ 00017 typedef unsigned long bitmap_block_t; 00018 00019 /** Size of a block of bits (in bits) */ 00020 #define BITMAP_BLKSIZE ( sizeof ( bitmap_block_t ) * 8 ) 00021 00022 /** 00023 * Block index within bitmap 00024 * 00025 * @v bit Bit index 00026 * @ret index Block index 00027 */ 00028 #define BITMAP_INDEX( bit ) ( (bit) / BITMAP_BLKSIZE ) 00029 00030 /** 00031 * Block mask within bitmap 00032 * 00033 * @v bit Bit index 00034 * @ret mask Block mask 00035 */ 00036 #define BITMAP_MASK( bit ) ( 1 << ( (bit) % BITMAP_BLKSIZE ) ) 00037 00038 /** A bitmap */ 00039 struct bitmap { 00040 /** Bitmap data */ 00041 bitmap_block_t *blocks; 00042 /** Length of the bitmap, in bits */ 00043 unsigned int length; 00044 /** Index of first gap in the bitmap */ 00045 unsigned int first_gap; 00046 }; 00047 00048 extern int bitmap_resize ( struct bitmap *bitmap, unsigned int new_length ); 00049 extern int bitmap_test ( struct bitmap *bitmap, unsigned int bit ); 00050 extern void bitmap_set ( struct bitmap *bitmap, unsigned int bit ); 00051 00052 /** 00053 * Free bitmap resources 00054 * 00055 * @v bitmap Bitmap 00056 */ 00057 static inline void bitmap_free ( struct bitmap *bitmap ) { 00058 free ( bitmap->blocks ); 00059 } 00060 00061 /** 00062 * Get first gap within bitmap 00063 * 00064 * @v bitmap Bitmap 00065 * @ret first_gap First gap 00066 * 00067 * The first gap is the first unset bit within the bitmap. 00068 */ 00069 static inline unsigned int bitmap_first_gap ( struct bitmap *bitmap ) { 00070 return bitmap->first_gap; 00071 } 00072 00073 /** 00074 * Check to see if bitmap is full 00075 * 00076 * @v bitmap Bitmap 00077 * @ret is_full Bitmap is full 00078 * 00079 * The bitmap is full if it has no gaps (i.e. no unset bits). 00080 */ 00081 static inline int bitmap_full ( struct bitmap *bitmap ) { 00082 return ( bitmap->first_gap == bitmap->length ); 00083 } 00084 00085 #endif /* _GPXE_BITMAP_H */
1.5.7.1