equal
deleted
inserted
replaced
|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Implements the avdtp allocators |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #include "avdtpAllocators.h" |
|
24 |
|
25 TInt TBitFieldAllocator::Get(TInt& aValue, TInt aMax, TInt aMin/*=0*/) |
|
26 { |
|
27 if (aMax<aMin) |
|
28 { |
|
29 return KErrArgument; |
|
30 } |
|
31 if ((aMax-aMin)>((8*sizeof(iBitField))-1)) |
|
32 { |
|
33 // this class supports 64 values/bits at present |
|
34 return KErrTooBig; |
|
35 } |
|
36 // bit 1 represents the use of val=min,bit 2 use of val=min+1, etc |
|
37 for (TInt bit=0;bit<=(aMax-aMin);bit++) |
|
38 { |
|
39 if (!(iBitField & (1<<bit))) |
|
40 { |
|
41 iMin = aMin; |
|
42 // it's free, mark it |
|
43 iBitField |= (1<<bit); |
|
44 aValue = bit+iMin; |
|
45 return KErrNone; |
|
46 } |
|
47 } |
|
48 return KErrInUse; |
|
49 } |
|
50 |
|
51 |
|
52 void TBitFieldAllocator::Free(TInt aValue) |
|
53 { |
|
54 TInt bitPos = aValue-iMin; |
|
55 #ifdef _DEBUG |
|
56 if (!(iBitField & (1<<bitPos))) |
|
57 { |
|
58 // freeing an unclaimed bit - maybe due to a leave, but allow checking |
|
59 __DEBUGGER(); |
|
60 } |
|
61 #endif |
|
62 //Clear the bit in iSpace corresponding to aBitPos |
|
63 iBitField &= (~(1<<bitPos)); |
|
64 } |
|
65 |
|
66 |