|
1 // Copyright (c) 1997-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 // |
|
15 |
|
16 #if !defined(__MBufManager_h__) |
|
17 #define __MBufManager_h__ |
|
18 |
|
19 #include <comms-infras/mbufsizeallocator.h> // for MBufSizeAllocator |
|
20 |
|
21 /** |
|
22 MBuf Private Heap Limits |
|
23 |
|
24 @internalTechnology |
|
25 */ |
|
26 const TUint KMBufDefaultHeapSize = 256 * 1024; |
|
27 |
|
28 class Nif; |
|
29 class CRequestAsyncAlloc; |
|
30 class CMBufPoolManager; |
|
31 class CMBufMemoryAllocator; |
|
32 |
|
33 class CMBufManager : public CBase |
|
34 /** |
|
35 @internalTechnology |
|
36 */ |
|
37 { |
|
38 friend class Nif; |
|
39 |
|
40 private: |
|
41 CMBufManager(); |
|
42 public: |
|
43 IMPORT_C ~CMBufManager(); |
|
44 IMPORT_C static CMBufManager* NewL(TInt aMaxHeapSize, MMBufSizeAllocator* &aMBufSizeAllocator); |
|
45 |
|
46 IMPORT_C RMBuf* AllocL(TInt aSize); |
|
47 IMPORT_C RMBuf* Alloc(TInt aSize); |
|
48 |
|
49 IMPORT_C void Free(RMBuf* aMBuf); |
|
50 IMPORT_C static void Panic(TMBufPanic aPanic); |
|
51 |
|
52 void CallBackAfterFree(); |
|
53 |
|
54 void StartRequest(RMBufAsyncRequest& aRequest); |
|
55 void CancelRequest(RMBufAsyncRequest& aRequest); |
|
56 |
|
57 static CDeltaTimer* Timer(); |
|
58 |
|
59 // Used to reference the single process-wide MBufManager from different threads+DLLs |
|
60 // Don't try to inline these - if TLS is in use then they need to be in this DLL |
|
61 IMPORT_C static CMBufManager* Context(); // Panics if no context! |
|
62 // A new thread/DLL needs to call this when the TLS handling is in use, ie in the |
|
63 // thread startup function, having obtained a pointer to the CMBufManager somehow |
|
64 // (eg caller passed in). Consider it as the thread/dll introducing itself to the |
|
65 // MBufMgr. "Pleased to meet you..." |
|
66 IMPORT_C void SetContext(); |
|
67 |
|
68 RMBuf* Alloc(TInt aSize, TInt aMinMBufSize); |
|
69 RMBuf* Alloc(TInt aSize, TInt aMinMBufSize, TInt aMaxMBufSize); |
|
70 RMBuf* Alloc(TInt aSize, TInt aMinMBufSize, TInt aMaxMBufSize, TBool aIsAllocPool); |
|
71 RMBuf* Alloc(TInt aSize, const RMBufChain& aMBufChain); |
|
72 |
|
73 // Metrics |
|
74 TInt BytesAvailable() const; |
|
75 TInt BytesAvailable(TInt aSize) const; |
|
76 TInt NextMBufSize(TInt aSize) const; |
|
77 TInt LargestMBufSize() const; |
|
78 |
|
79 void WatchDogReset(); |
|
80 |
|
81 private: |
|
82 |
|
83 void ConstructL(TInt aMaxHeapSize); |
|
84 |
|
85 static TInt WatchDogExpire(TAny* aPtr); |
|
86 static TInt FreeCallBack(TAny* aPtr); |
|
87 void CompleteAsyncAllocs(TBool aIsAllocPool); |
|
88 |
|
89 private: |
|
90 |
|
91 RWorkerLock iAsynAllocLock; |
|
92 |
|
93 CMBufPoolManager* iMBufPoolManager; |
|
94 |
|
95 TDblQue<RMBufAsyncRequest> iAllocsPending; |
|
96 CDeltaTimer* iTimer; // The global delta timer. |
|
97 TThreadId iTimerThreadId; |
|
98 TDeltaTimerEntry iWatchDog; |
|
99 TBool iWatchDogIsPending; |
|
100 CAsyncCallBack* iFreeCB; |
|
101 CRequestAsyncAlloc* iRequestAsyncAlloc; |
|
102 |
|
103 public: |
|
104 IMPORT_C static void __DbgCheckChain(RMBuf* aMBuf, TMBufType aType, TInt aLength, TInt aSize); |
|
105 IMPORT_C TInt __DbgCheckBuffer(RMBuf* aBuf); |
|
106 IMPORT_C RMBuf* __DbgMBufChain(); |
|
107 IMPORT_C RMBuf* __DbgMBufChain(TUint aMBufSize); |
|
108 IMPORT_C void __DbgSetPoolLimit(TInt aCount); |
|
109 IMPORT_C void __DbgSetPoolLimit(TInt aCount, TUint aMBufSize); |
|
110 IMPORT_C void __DbgSetFailAfter(TInt aCount=0); |
|
111 IMPORT_C TUint __DbgGetBufSpace(); |
|
112 IMPORT_C TUint __DbgGetBufSpace(TUint aMBufSize); |
|
113 IMPORT_C TUint __DbgGetBufTotal(); |
|
114 IMPORT_C TUint __DbgGetBufTotal(TUint aMBufSize); |
|
115 IMPORT_C TInt __DbgGetHeapSize(); |
|
116 |
|
117 private: |
|
118 TInt iDbgFailAfter; // fail allocation request of pool within pool chain |
|
119 |
|
120 #ifdef SYMBIAN_NETWORKING_PERFMETRICS |
|
121 static TBool AddToPerfLog(TAny* aSelf, TDes8& aBuffer, TDes8Overflow* aOverflowHandler); |
|
122 |
|
123 enum |
|
124 { |
|
125 KBucketSize = 128, // Should be a power of 2 for better perf |
|
126 KNumBuckets = 13 |
|
127 }; |
|
128 TUint iBuckets[KNumBuckets]; |
|
129 TUint iNumOOBs; |
|
130 #endif |
|
131 }; |
|
132 |
|
133 #endif |