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 |
760 r=((r+aBase+alignmask)&~alignmask)-aBase; |
803 r=((r+aBase+alignmask)&~alignmask)-aBase; |
761 return r; |
804 return r; |
762 } |
805 } |
763 |
806 |
764 |
807 |
765 /** Allocates a specific range of bit positions. |
|
766 |
|
767 The specified range must lie within the total range for this allocator but it is |
|
768 not necessary that all the positions are currently free. |
|
769 |
|
770 @param aStart First position to allocate. |
|
771 @param aLength Number of consecutive positions to allocate, must be >0. |
|
772 @return The number of previously free positions that were allocated. |
|
773 */ |
|
774 EXPORT_C TUint TBitMapAllocator::SelectiveAlloc(TInt aStart, TInt aLength) |
|
775 { |
|
776 __ASSERT_ALWAYS(TUint(aStart) < TUint(iSize), TBMA_FAULT()); |
|
777 __ASSERT_ALWAYS(TUint(aStart + aLength) >= TUint(aStart), TBMA_FAULT()); |
|
778 __ASSERT_ALWAYS(TUint(aStart + aLength) <= TUint(iSize), TBMA_FAULT()); |
|
779 TInt wix = aStart >> 5; |
|
780 TInt sbit = aStart & 31; |
|
781 TUint32* pW = iMap + wix; |
|
782 iAvail -= aLength; // update free count assuming no positions already allocated |
|
783 TInt ebit = sbit + aLength; |
|
784 if (ebit < 32) |
|
785 { |
|
786 TUint32 b = ((0xffffffffu >> aLength) >> sbit) | ~(0xffffffffu >> sbit); |
|
787 TUint32 w = *pW; |
|
788 *pW = w & b; // mark all positions allocated |
|
789 TUint allocated = __e32_bit_count_32(~w & ~b); |
|
790 iAvail += allocated; // increase free count by number of positions already allocated |
|
791 return aLength - allocated; |
|
792 } |
|
793 TUint32 b = ~(0xffffffffu >> sbit); |
|
794 while (ebit > 0) |
|
795 { |
|
796 TUint32 w = *pW; |
|
797 *pW++ = w & b; // mark all positions allocated |
|
798 TUint allocated = __e32_bit_count_32(~w & ~b); |
|
799 iAvail += allocated; // increase free count by number of positions already allocated |
|
800 aLength -= allocated; |
|
801 ebit -= 32; |
|
802 b = (ebit >= 32)? 0 : 0xffffffff >> ebit; |
|
803 } |
|
804 return aLength; |
|
805 } |
|
806 |
|
807 |
|
808 /** Copies a range from another allocator, mark remainder as occupied. |
808 /** Copies a range from another allocator, mark remainder as occupied. |
809 |
809 |
810 Values of bit positions from aFirst to aFirst+aLen-1 inclusive in allocator |
810 Values of bit positions from aFirst to aFirst+aLen-1 inclusive in allocator |
811 aA are copied to bit positions in this allocator starting with aFirst mod 32. |
811 aA are copied to bit positions in this allocator starting with aFirst mod 32. |
812 Remaining bit positions in this allocator are marked as occupied. |
812 Remaining bit positions in this allocator are marked as occupied. |