Changeset 6e75f2d in mainline
- Timestamp:
- 2013-09-12T11:45:34Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3731d31
- Parents:
- c5396c1
- Location:
- kernel/generic
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/adt/bitmap.h
rc5396c1 r6e75f2d 44 44 size_t elements; 45 45 uint8_t *bits; 46 size_t next_fit; 46 47 } bitmap_t; 47 48 … … 59 60 } else { 60 61 bitmap->bits[byte] &= ~mask; 62 bitmap->next_fit = byte; 61 63 } 62 64 } -
kernel/generic/src/adt/bitmap.c
rc5396c1 r6e75f2d 100 100 bitmap->elements = elements; 101 101 bitmap->bits = (uint8_t *) data; 102 bitmap->next_fit = 0; 102 103 } 103 104 … … 116 117 return; 117 118 119 size_t start_byte = start / BITMAP_ELEMENT; 118 120 size_t aligned_start = ALIGN_UP(start, BITMAP_ELEMENT); 119 121 … … 129 131 if (start + count < aligned_start) { 130 132 /* Set bits in the middle of byte. */ 131 bitmap->bits[start / BITMAP_ELEMENT] |=133 bitmap->bits[start_byte] |= 132 134 ((1 << lub) - 1) << (start & BITMAP_REMAINER); 133 135 return; … … 136 138 if (lub) { 137 139 /* Make sure to set any leading unaligned bits. */ 138 bitmap->bits[start / BITMAP_ELEMENT] |=140 bitmap->bits[start_byte] |= 139 141 ~((1 << (BITMAP_ELEMENT - lub)) - 1); 140 142 } … … 169 171 return; 170 172 173 size_t start_byte = start / BITMAP_ELEMENT; 171 174 size_t aligned_start = ALIGN_UP(start, BITMAP_ELEMENT); 172 175 … … 182 185 if (start + count < aligned_start) { 183 186 /* Set bits in the middle of byte */ 184 bitmap->bits[start / BITMAP_ELEMENT] &=187 bitmap->bits[start_byte] &= 185 188 ~(((1 << lub) - 1) << (start & BITMAP_REMAINER)); 186 189 return; … … 189 192 if (lub) { 190 193 /* Make sure to clear any leading unaligned bits. */ 191 bitmap->bits[start / BITMAP_ELEMENT] &=194 bitmap->bits[start_byte] &= 192 195 (1 << (BITMAP_ELEMENT - lub)) - 1; 193 196 } … … 206 209 ~((1 << tab) - 1); 207 210 } 211 212 bitmap->next_fit = start_byte; 208 213 } 209 214 … … 269 274 return false; 270 275 271 size_t bytes = bitmap_size(bitmap->elements); 272 273 for (size_t byte = 0; byte < bytes; byte++) { 276 size_t size = bitmap_size(bitmap->elements); 277 278 for (size_t pos = 0; pos < size; pos++) { 279 size_t byte = (bitmap->next_fit + pos) % size; 280 274 281 /* Skip if the current byte has all bits set */ 275 282 if (bitmap->bits[byte] == ALL_ONES) … … 288 295 289 296 if (!bitmap_get_fast(bitmap, i)) { 290 bool continuous = true;297 size_t continuous = 1; 291 298 292 299 for (size_t j = 1; j < count; j++) { 293 if ((i + j >= bitmap->elements) || 294 (bitmap_get_fast(bitmap, i + j))) { 295 continuous = false; 300 if ((i + j < bitmap->elements) && 301 (!bitmap_get_fast(bitmap, i + j))) 302 continuous++; 303 else 296 304 break; 297 }298 305 } 299 306 300 if (continuous ) {307 if (continuous == count) { 301 308 if (index != NULL) { 302 309 bitmap_set_range(bitmap, i, count); 310 bitmap->next_fit = i / BITMAP_ELEMENT; 303 311 *index = i; 304 312 } 305 313 306 314 return true; 307 } 315 } else 316 i += continuous; 308 317 } 309 318 }
Note:
See TracChangeset
for help on using the changeset viewer.