|
1 /* |
|
2 * Copyright (c) 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 the License "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 #ifndef _MEMMANAGER_H_ |
|
20 #define _MEMMANAGER_H_ |
|
21 |
|
22 #include <e32def.h> // For TUint16 |
|
23 #include <e32cmn.h> // For TDesC8 |
|
24 #include "memapi.h" // For MemApi |
|
25 |
|
26 // Forward declarations |
|
27 class DPlatChunkHw; |
|
28 class DMemPool; |
|
29 |
|
30 |
|
31 const TUint8 KPoolHighWaterLimit( 80 ); |
|
32 |
|
33 const TInt KPoolAllocateDfcPriority( 7 ); |
|
34 const TInt KPoolDeleteDfcPriority( 1 ); |
|
35 |
|
36 _LIT( KMemManagerDfcQThreadName, "MemManagerDfcQueueThread" ); |
|
37 |
|
38 /* |
|
39 * Class implementing the ISCEs internal MEM API. |
|
40 */ |
|
41 NONSHARABLE_CLASS( DMemManager ) : public DBase, public MemApi |
|
42 { |
|
43 public: |
|
44 |
|
45 //Functions |
|
46 /* |
|
47 * Constructor |
|
48 */ |
|
49 DMemManager(); |
|
50 |
|
51 /* |
|
52 * Destructor |
|
53 */ |
|
54 ~DMemManager(); |
|
55 |
|
56 // From MemApi |
|
57 /* |
|
58 * See comments from MemApi. |
|
59 * Can be called in 1...N kernel thread contexts. |
|
60 */ |
|
61 static TDes8& AllocBlock( const TUint16 aSize ); |
|
62 |
|
63 /* |
|
64 * See comments from MemApi. |
|
65 * Can be called in 1...N kernel thread contexts. |
|
66 */ |
|
67 static void DeallocBlock( TDes8& aBlock ); |
|
68 |
|
69 |
|
70 // Internal data |
|
71 static DMemManager* iThisptr; |
|
72 |
|
73 static TDfcQue* iDfcQueue; |
|
74 |
|
75 static void PoolAllocateDfc( TAny* aPtr ); |
|
76 static void PoolDeleteDfc( TAny* aPtr ); |
|
77 |
|
78 TDfc* iPoolAllocateDfc; |
|
79 TDfc* iPoolDeleteDfc; |
|
80 |
|
81 private: |
|
82 |
|
83 /* |
|
84 * Internal class for handling memory pools consisting of linked lists. |
|
85 */ |
|
86 NONSHARABLE_CLASS( DMemPool ) : public DBase |
|
87 { |
|
88 private: |
|
89 |
|
90 struct sUnit //The type of the unit of linkedlist |
|
91 { |
|
92 struct sUnit *iPrev, *iNext; |
|
93 TPtr8* iMemPtr; |
|
94 }; |
|
95 |
|
96 public: |
|
97 |
|
98 DMemPool( const TUint16 aUnitSize, const TUint16 aUnitNum ); |
|
99 ~DMemPool(); |
|
100 |
|
101 TPtr8* Alloc( const TUint16 aSize ); //Allocate memory unit |
|
102 TBool Free( const TUint8* aBlockAddress ); |
|
103 |
|
104 private: |
|
105 |
|
106 //Manage all units with two linkedlist |
|
107 struct sUnit* iAllocatedMemBlock; //Head pointer to Allocated linkedlist |
|
108 struct sUnit* iFreeMemBlock; //Head pointer to Free linkedlist |
|
109 |
|
110 public: |
|
111 |
|
112 //Memory pool features |
|
113 TUint8* iMemoryArea; |
|
114 TInt iPoolSize; |
|
115 TUint16 iBlockSize; |
|
116 TUint16 iBlockNum; |
|
117 TUint16 iBlockUsage; |
|
118 TUint16 iHighWaterMark; |
|
119 TBool iCopyPoolInUse; |
|
120 |
|
121 private: |
|
122 |
|
123 //Environment related variables |
|
124 DPlatChunkHw* iHwChunk; |
|
125 TPhysAddr iPhysicalAddress; |
|
126 |
|
127 }; |
|
128 |
|
129 |
|
130 public: |
|
131 |
|
132 NFastMutex* iFastMutex; |
|
133 RArray<DMemPool*> iMemPond; |
|
134 RArray<DMemPool*> iPoolCreateQueue; |
|
135 RArray<DMemPool*> iPoolDeleteQueue; |
|
136 |
|
137 }; |
|
138 |
|
139 #endif // _MEMMANAGER_H_ |