428 b=0xffffffffu; |
428 b=0xffffffffu; |
429 ebit-=32; |
429 ebit-=32; |
430 if (ebit<32) |
430 if (ebit<32) |
431 b=~(b>>ebit); |
431 b=~(b>>ebit); |
432 } |
432 } |
|
433 } |
|
434 |
|
435 |
|
436 /** Allocates a specific range of bit positions. |
|
437 |
|
438 The specified range must lie within the total range for this allocator but it is |
|
439 not necessary that all the positions are currently free. |
|
440 |
|
441 @param aStart First position to allocate. |
|
442 @param aLength Number of consecutive positions to allocate, must be >0. |
|
443 @return The number of previously free positions that were allocated. |
|
444 */ |
|
445 EXPORT_C TUint TBitMapAllocator::SelectiveAlloc(TInt aStart, TInt aLength) |
|
446 { |
|
447 __ASSERT_ALWAYS(TUint(aStart) < TUint(iSize), TBMA_FAULT()); |
|
448 __ASSERT_ALWAYS(TUint(aStart + aLength) >= TUint(aStart), TBMA_FAULT()); |
|
449 __ASSERT_ALWAYS(TUint(aStart + aLength) <= TUint(iSize), TBMA_FAULT()); |
|
450 TInt wix = aStart >> 5; |
|
451 TInt sbit = aStart & 31; |
|
452 TUint32* pW = iMap + wix; |
|
453 iAvail -= aLength; // update free count assuming no positions already allocated |
|
454 TInt ebit = sbit + aLength; |
|
455 if (ebit < 32) |
|
456 { |
|
457 TUint32 b = ((0xffffffffu >> aLength) >> sbit) | ~(0xffffffffu >> sbit); |
|
458 TUint32 w = *pW; |
|
459 *pW = w & b; // mark all positions allocated |
|
460 TUint allocated = __e32_bit_count_32(~w & ~b); |
|
461 iAvail += allocated; // increase free count by number of positions already allocated |
|
462 return aLength - allocated; |
|
463 } |
|
464 TUint32 b = ~(0xffffffffu >> sbit); |
|
465 while (ebit > 0) |
|
466 { |
|
467 TUint32 w = *pW; |
|
468 *pW++ = w & b; // mark all positions allocated |
|
469 TUint allocated = __e32_bit_count_32(~w & ~b); |
|
470 iAvail += allocated; // increase free count by number of positions already allocated |
|
471 aLength -= allocated; |
|
472 ebit -= 32; |
|
473 b = (ebit >= 32)? 0 : 0xffffffff >> ebit; |
|
474 } |
|
475 return aLength; |
433 } |
476 } |
434 |
477 |
435 |
478 |
436 /** Tests whether a specific range of bit positions are all free. |
479 /** Tests whether a specific range of bit positions are all free. |
437 |
480 |