79 @param aClientName the unique identification of CCacheMemoryClient |
79 @param aClientName the unique identification of CCacheMemoryClient |
80 @param aOffsetInBytes the offset to the base position of CCacheMemoryManager it registered |
80 @param aOffsetInBytes the offset to the base position of CCacheMemoryManager it registered |
81 */ |
81 */ |
82 void CCacheMemoryClient::ConstructL(const TDesC& aClientName, TUint32 aOffsetInBytes) |
82 void CCacheMemoryClient::ConstructL(const TDesC& aClientName, TUint32 aOffsetInBytes) |
83 { |
83 { |
|
84 __PRINT4(_L("CCacheMemoryClient::ConstructL(%S, min=%d, max=%d, base=0x%X)"), &aClientName, iMinSizeInSegs, iMaxSizeInSegs, iBase); |
84 iName = HBufC::NewMaxL(aClientName.Length()); |
85 iName = HBufC::NewMaxL(aClientName.Length()); |
85 *iName = aClientName; |
86 *iName = aClientName; |
86 iSegSizeInBytesLog2 = iManager.SegmentSizeInBytesLog2(); |
87 iSegSizeInBytesLog2 = iManager.SegmentSizeInBytesLog2(); |
87 iSegSizeInBytes = 1 << iSegSizeInBytesLog2; |
88 iSegSizeInBytes = 1 << iSegSizeInBytesLog2; |
88 iReusablePagePool.Close(); |
89 iReusablePagePool.Close(); |
91 iReservedRegionMarkInSegs = iMinSizeInSegs; |
92 iReservedRegionMarkInSegs = iMinSizeInSegs; |
92 TInt r = iManager.AllocateAndLockSegments(iBase, iReservedRegionMarkInSegs); |
93 TInt r = iManager.AllocateAndLockSegments(iBase, iReservedRegionMarkInSegs); |
93 ASSERT(r==KErrNone); |
94 ASSERT(r==KErrNone); |
94 User::LeaveIfError(r); |
95 User::LeaveIfError(r); |
95 iTouchedRegionFlag = 0; |
96 iTouchedRegionFlag = 0; |
96 __PRINT4(_L("CCacheMemoryClient::ConstructL(%S, min=%d, max=%d, base=0x%X)"), &aClientName, iMinSizeInSegs, iMaxSizeInSegs, iBase); |
97 __PRINT(_L("CCacheMemoryClient::ConstructL() return 0")); |
97 } |
98 } |
98 |
99 |
99 /** |
100 /** |
100 Reset the client state, this is normally issued from the cache it connected with. |
101 Reset the client state, this is normally issued from the cache it connected with. |
101 For exmaple, a FAT volume is dismounted so the directory cache needs to be reset. |
102 For exmaple, a FAT volume is dismounted so the directory cache needs to be reset. |
107 */ |
108 */ |
108 EXPORT_C void CCacheMemoryClient::Reset() |
109 EXPORT_C void CCacheMemoryClient::Reset() |
109 { |
110 { |
110 __PRINT3(_L("CCacheMemoryClient::Reset(%S, reserved=%d, touched=%d)"), iName, iReservedRegionMarkInSegs, iTouchedRegionFlag); |
111 __PRINT3(_L("CCacheMemoryClient::Reset(%S, reserved=%d, touched=%d)"), iName, iReservedRegionMarkInSegs, iTouchedRegionFlag); |
111 |
112 |
112 // in case that client user has incorrectly decommited reserved region (normally on destruction), |
113 // reset the cache memeory client to initial states: |
113 // we should re-commit reserved region here to prepare the next connection. |
114 // 1. all memory that have been 'touched' should be decommitted |
114 TInt r = DecommitSegments(iBase, iReservedRegionMarkInSegs); |
115 // 2. the reserved region of memory should be re-locked |
115 if (r != KErrNone) // this 'if() {}' is to remove build warnings in debug mode, same is below |
116 |
116 { |
117 // if we have touched more than reserved region of memory, we shall decommit all of them |
117 ASSERT(0); |
|
118 } |
|
119 |
|
120 r = iManager.AllocateAndLockSegments(iBase, iReservedRegionMarkInSegs); |
|
121 if (r != KErrNone) |
|
122 { |
|
123 ASSERT(0); |
|
124 } |
|
125 |
|
126 // if we have touched more than reserved, we also need to make sure it's decommitted. |
|
127 if (iTouchedRegionFlag > iReservedRegionMarkInSegs) |
118 if (iTouchedRegionFlag > iReservedRegionMarkInSegs) |
128 { |
119 { |
129 TInt r = iManager.DecommitSegments(iBase + (iReservedRegionMarkInSegs << iSegSizeInBytesLog2), iTouchedRegionFlag - iReservedRegionMarkInSegs); |
120 TInt r = DecommitSegments(iBase, iTouchedRegionFlag); |
130 if (r != KErrNone) |
121 if (r != KErrNone) // this 'if() {}' is to remove build warnings in debug mode, same is below |
131 { |
122 { |
132 ASSERT(0); |
123 ASSERT(0); |
133 } |
124 } |
134 } |
125 } |
135 |
126 else // otherwise we decommit the reserved region of memory only. |
|
127 { |
|
128 TInt r = DecommitSegments(iBase, iReservedRegionMarkInSegs); |
|
129 if (r != KErrNone) // this 'if() {}' is to remove build warnings in debug mode, same is below |
|
130 { |
|
131 ASSERT(0); |
|
132 } |
|
133 } |
|
134 |
|
135 // re-lock the reserved region of memory |
|
136 TInt r = iManager.AllocateAndLockSegments(iBase, iReservedRegionMarkInSegs); |
|
137 if (r != KErrNone) |
|
138 { |
|
139 ASSERT(0); |
|
140 } |
|
141 |
136 iTouchedRegionFlag = 0; |
142 iTouchedRegionFlag = 0; |
137 iReusablePagePool.Close(); |
143 iReusablePagePool.Close(); |
138 iReusablePagePool.Reserve(iReservedRegionMarkInSegs); |
144 iReusablePagePool.Reserve(iReservedRegionMarkInSegs); |
139 } |
145 } |
140 |
146 |
146 @internalTechnology |
152 @internalTechnology |
147 @released |
153 @released |
148 */ |
154 */ |
149 EXPORT_C TUint8* CCacheMemoryClient::AllocateAndLockSegments(TUint32 aSegmentCount) |
155 EXPORT_C TUint8* CCacheMemoryClient::AllocateAndLockSegments(TUint32 aSegmentCount) |
150 { |
156 { |
151 __PRINT3(_L("CCacheMemoryClient::AllocateAndLockSegments(%S, reserved=%d, touched=%d)"), iName, iReservedRegionMarkInSegs, iTouchedRegionFlag); |
157 __PRINT4(_L("CCacheMemoryClient::AllocateAndLockSegments(%S, segs=%d, reserved=%d, touched=%d)"), iName, aSegmentCount, iReservedRegionMarkInSegs, iTouchedRegionFlag); |
152 // __PRINT2(_L("iBase = 0x%x, segcnt = %d"), iBase, aSegmentCount); |
158 // __PRINT2(_L("iBase = 0x%x, segcnt = %d"), iBase, aSegmentCount); |
153 TUint8* addr = NULL; |
159 TUint8* addr = NULL; |
154 // if we are walking through the reserved region first time, we should |
160 // if we are walking through the reserved region first time, we should |
155 // make assumption that this area is locked already |
161 // make assumption that this area is locked already |
156 if (iTouchedRegionFlag + aSegmentCount <= iReservedRegionMarkInSegs) |
162 if (iTouchedRegionFlag + aSegmentCount <= iReservedRegionMarkInSegs) |