kernel/eka/klib/bma.cpp
branchRCL_3
changeset 26 c734af59ce98
parent 0 a41df078684a
child 28 5b5d147c7838
equal deleted inserted replaced
24:41f0cfe18c80 26:c734af59ce98
   760 		r=((r+aBase+alignmask)&~alignmask)-aBase;
   760 		r=((r+aBase+alignmask)&~alignmask)-aBase;
   761 	return r;
   761 	return r;
   762 	}
   762 	}
   763 
   763 
   764 
   764 
       
   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 
   765 /** Copies a range from another allocator, mark remainder as occupied.
   808 /** Copies a range from another allocator, mark remainder as occupied.
   766 
   809 
   767 	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
   768 	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.
   769 	Remaining bit positions in this allocator are marked as occupied.
   812 	Remaining bit positions in this allocator are marked as occupied.