|
1 // Copyright (c) 2008-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 // @file |
|
15 // @internalComponent |
|
16 // |
|
17 // |
|
18 |
|
19 #ifndef __RCHUNKPOOL_H_ |
|
20 #define __RCHUNKPOOL_H_ |
|
21 |
|
22 #include "cmemchunk.h" |
|
23 |
|
24 class RChunkPool |
|
25 { |
|
26 public: |
|
27 RChunkPool ( TInt aBlockSize, TInt aThresholdValue, TInt aMinGrowth, CChunkManager& aChunkManager ); |
|
28 RChunkPool ( CChunkManager& aChunkManager, TInt aBlockSize ); |
|
29 |
|
30 void OpenL (); |
|
31 void Close (); |
|
32 |
|
33 TInt Alloc ( RMemCellList& aList, TInt aSize ); |
|
34 TInt GrowAndAlloc ( RMemCellList& aList, TInt aSize, TInt aNumBlocks ); |
|
35 void FreeToPool ( RMemCell* aMemCell ); |
|
36 void AppendToFreeList ( CMemChunk* aChunk ); |
|
37 static TInt Compare ( const RChunkPool& aLHSPool, const RChunkPool& aRHSPool ); |
|
38 |
|
39 TInt BlockSize () const |
|
40 { |
|
41 return iBlockSize; |
|
42 } |
|
43 |
|
44 void Wait () |
|
45 { |
|
46 iFreeListLock.Wait (); |
|
47 } |
|
48 |
|
49 void Signal () |
|
50 { |
|
51 iFreeListLock.Signal (); |
|
52 } |
|
53 |
|
54 void SetThreshold ( TInt aThreshold ) |
|
55 { |
|
56 iThresholdValue = aThreshold; |
|
57 } |
|
58 |
|
59 void SetGrowth ( TInt aGrowth ) |
|
60 { |
|
61 iMinGrowth = aGrowth; |
|
62 } |
|
63 |
|
64 void Append ( CMemChunk* aNewChunk ) |
|
65 { |
|
66 iAllocatedChunks.Append ( aNewChunk ); |
|
67 } |
|
68 |
|
69 TInt FreeSpace () |
|
70 { |
|
71 return iFreeSpace; |
|
72 } |
|
73 |
|
74 CChunkManager& ChunkManager () |
|
75 { |
|
76 return iChunkManager; |
|
77 } |
|
78 |
|
79 private: |
|
80 TInt GrowPool ( TUint aNumBlocks ); |
|
81 |
|
82 private: |
|
83 TInt iBlockSize; |
|
84 RPointerArray<CMemChunk> iAllocatedChunks; |
|
85 CChunkManager& iChunkManager; |
|
86 RMemCellList iFreeBlocks; |
|
87 RFastLock iFreeListLock; |
|
88 TInt iFreeSpace; |
|
89 TInt iUsedSpace; //TODO: can be removed??? |
|
90 TInt iThresholdValue; |
|
91 TInt iMinGrowth; |
|
92 }; |
|
93 |
|
94 #endif /*__RCHUNKPOOL_H_*/ |