|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef ALLOCATOR_H |
|
21 #define ALLOCATOR_H |
|
22 |
|
23 #include <e32cmn.h> |
|
24 |
|
25 class DMutex; |
|
26 |
|
27 /** |
|
28 Keeps track of what address ranges are available |
|
29 Address ranges will be size aligned. ie. 4k range will be aligned to 4k |
|
30 boundary, 1k range will be aligned to 1k boundary |
|
31 */ |
|
32 class TAddressAllocator |
|
33 { |
|
34 public: |
|
35 TAddressAllocator(TLinAddr aMaxSize); |
|
36 ~TAddressAllocator(); |
|
37 TInt Allocate(TLinAddr& aAddress, TLinAddr aSize); |
|
38 TInt DeAllocate(TLinAddr aAddress); |
|
39 private: |
|
40 /** |
|
41 A contiguous address region. |
|
42 */ |
|
43 struct TRange |
|
44 { |
|
45 TRange(TLinAddr aStart, TLinAddr aLength, TBool aAllocated) |
|
46 :iAllocated(aAllocated), iStart(aStart), iLength(aLength) |
|
47 { |
|
48 } |
|
49 inline TLinAddr End() const |
|
50 { return iStart+iLength-1;} |
|
51 |
|
52 static TInt OrderByStart(const TRange& aKeyRange, const TRange& aRange); |
|
53 |
|
54 TBool iAllocated; |
|
55 TLinAddr iStart; |
|
56 TLinAddr iLength; |
|
57 }; |
|
58 |
|
59 void DoAllocate(TLinAddr aAddress, TLinAddr aSize, TInt aIndex); |
|
60 void Remove(TInt aIndex); |
|
61 #if defined (_DEBUG) |
|
62 void Print(); |
|
63 TBool InvariantCheck(); |
|
64 #endif |
|
65 |
|
66 |
|
67 const TLinAddr iMaxSize; |
|
68 RArray<TRange> iRangeList; //a list of contiguous, non-overlapping address regions. |
|
69 DMutex* iMutex; |
|
70 }; |
|
71 |
|
72 #endif //ALLOCATOR_H |