Changeset da88a079 in mainline for kernel/generic/src/adt/bitmap.c
- Timestamp:
- 2010-11-09T21:14:00Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e9e5b9ab
- Parents:
- a13c6bc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/adt/bitmap.c
ra13c6bc rda88a079 32 32 /** 33 33 * @file 34 * @brief 34 * @brief Implementation of bitmap ADT. 35 35 * 36 36 * This file implements bitmap ADT and provides functions for … … 51 51 * No portion of the bitmap is set or cleared by this function. 52 52 * 53 * @param bitmap 54 * @param map 55 * @param bits 53 * @param bitmap Bitmap structure. 54 * @param map Address of the memory used to hold the map. 55 * @param bits Number of bits stored in bitmap. 56 56 */ 57 57 void bitmap_initialize(bitmap_t *bitmap, uint8_t *map, size_t bits) … … 63 63 /** Set range of bits. 64 64 * 65 * @param bitmap 66 * @param start 67 * @param bits 65 * @param bitmap Bitmap structure. 66 * @param start Starting bit. 67 * @param bits Number of bits to set. 68 68 */ 69 69 void bitmap_set_range(bitmap_t *bitmap, size_t start, size_t bits) … … 71 71 size_t i = 0; 72 72 size_t aligned_start; 73 size_t lub; 74 size_t amb; 75 size_t tab; 73 size_t lub; /* leading unaligned bits */ 74 size_t amb; /* aligned middle bits */ 75 size_t tab; /* trailing aligned bits */ 76 76 77 77 ASSERT(start + bits <= bitmap->bits); … … 82 82 tab = amb % 8; 83 83 84 if ( start + bits < aligned_start ) { 85 /* 86 * Set bits in the middle of byte 87 */ 88 bitmap->map[start / 8] |= ((1 << lub)-1) << (start&7); 89 return; 84 if (start + bits < aligned_start) { 85 /* Set bits in the middle of byte. */ 86 bitmap->map[start / 8] |= ((1 << lub) - 1) << (start & 7); 87 return; 90 88 } 91 89 92 90 if (lub) { 93 /* 94 * Make sure to set any leading unaligned bits. 95 */ 91 /* Make sure to set any leading unaligned bits. */ 96 92 bitmap->map[start / 8] |= ~((1 << (8 - lub)) - 1); 97 93 } 98 94 for (i = 0; i < amb / 8; i++) { 99 /* 100 * The middle bits can be set byte by byte. 101 */ 95 /* The middle bits can be set byte by byte. */ 102 96 bitmap->map[aligned_start / 8 + i] = ALL_ONES; 103 97 } 104 98 if (tab) { 105 /* 106 * Make sure to set any trailing aligned bits. 107 */ 99 /* Make sure to set any trailing aligned bits. */ 108 100 bitmap->map[aligned_start / 8 + i] |= (1 << tab) - 1; 109 101 } … … 113 105 /** Clear range of bits. 114 106 * 115 * @param bitmap 116 * @param start 117 * @param bits 107 * @param bitmap Bitmap structure. 108 * @param start Starting bit. 109 * @param bits Number of bits to clear. 118 110 */ 119 111 void bitmap_clear_range(bitmap_t *bitmap, size_t start, size_t bits) … … 121 113 size_t i = 0; 122 114 size_t aligned_start; 123 size_t lub; 124 size_t amb; 125 size_t tab; 115 size_t lub; /* leading unaligned bits */ 116 size_t amb; /* aligned middle bits */ 117 size_t tab; /* trailing aligned bits */ 126 118 127 119 ASSERT(start + bits <= bitmap->bits); … … 132 124 tab = amb % 8; 133 125 134 if ( start + bits < aligned_start ) 135 { 136 /* 137 * Set bits in the middle of byte 138 */ 139 bitmap->map[start / 8] &= ~(((1 << lub)-1) << (start&7)); 140 return; 126 if (start + bits < aligned_start) { 127 /* Set bits in the middle of byte */ 128 bitmap->map[start / 8] &= ~(((1 << lub) - 1) << (start & 7)); 129 return; 141 130 } 142 131 143 144 132 if (lub) { 145 /* 146 * Make sure to clear any leading unaligned bits. 147 */ 133 /* Make sure to clear any leading unaligned bits. */ 148 134 bitmap->map[start / 8] &= (1 << (8 - lub)) - 1; 149 135 } 150 136 for (i = 0; i < amb / 8; i++) { 151 /* 152 * The middle bits can be cleared byte by byte. 153 */ 137 /* The middle bits can be cleared byte by byte. */ 154 138 bitmap->map[aligned_start / 8 + i] = ALL_ZEROES; 155 139 } 156 140 if (tab) { 157 /* 158 * Make sure to clear any trailing aligned bits. 159 */ 141 /* Make sure to clear any trailing aligned bits. */ 160 142 bitmap->map[aligned_start / 8 + i] &= ~((1 << tab) - 1); 161 143 } … … 165 147 /** Copy portion of one bitmap into another bitmap. 166 148 * 167 * @param dst 168 * @param src 169 * @param bits 149 * @param dst Destination bitmap. 150 * @param src Source bitmap. 151 * @param bits Number of bits to copy. 170 152 */ 171 153 void bitmap_copy(bitmap_t *dst, bitmap_t *src, size_t bits)
Note:
See TracChangeset
for help on using the changeset viewer.