25 |
25 |
26 #include "sf_memory_man.h" |
26 #include "sf_memory_man.h" |
27 #include "sf_memory_client.h" |
27 #include "sf_memory_client.h" |
28 #include "sl_cache.h" |
28 #include "sl_cache.h" |
29 #include <e32hashtab.h> |
29 #include <e32hashtab.h> |
30 #include <f32dbg.h> |
|
31 |
30 |
32 //--------------------------------------------------------------------------------------------------------------------------------- |
31 //--------------------------------------------------------------------------------------------------------------------------------- |
33 class CDynamicDirCache; |
32 class CDynamicDirCache; |
34 |
33 |
35 |
34 |
131 void MakePageMRU(TInt64 aPos); |
130 void MakePageMRU(TInt64 aPos); |
132 TUint32 PageSizeInBytesLog2() const; |
131 TUint32 PageSizeInBytesLog2() const; |
133 |
132 |
134 TUint32 PageSizeInSegs() const; |
133 TUint32 PageSizeInSegs() const; |
135 |
134 |
136 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
137 // Debugging functions |
135 // Debugging functions |
138 void Dump(); |
136 void Dump(); |
139 void Info(TDirCacheInfo* aInfo) const; |
137 void Info() const; |
140 #endif //#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
141 |
138 |
142 protected: |
139 protected: |
143 CDynamicDirCache(TDriveInterface& aDrive, TUint32 aMinSizeInBytes, TUint32 aMaxSizeInBytes, TUint32 aPageSizeInBytesLog2, TUint32 aWrGranularityLog2); |
140 CDynamicDirCache(TDriveInterface& aDrive, TUint32 aMinSizeInBytes, TUint32 aMaxSizeInBytes, TUint32 aPageSizeInBytesLog2, TUint32 aWrGranularityLog2); |
144 void ConstructL(const TDesC& aClientName); |
141 void ConstructL(const TDesC& aClientName); |
145 |
142 |
146 void ReadDataFromSinglePageL(TInt64 aPos, TInt aLength, TDes8& aDes); |
143 void ReadDataFromSinglePageL(TInt64 aPos, TInt aLength, TDes8& aDes); |
147 TDynamicDirCachePage* WriteDataOntoSinglePageL(TInt64 aPos, const TUint8* aData, TUint32 aDataLen); |
144 TDynamicDirCachePage* WriteDataOntoSinglePageL(TInt64 aPos, const TUint8* aData, TUint32 aDataLen); |
148 |
145 |
149 TDynamicDirCachePage* FindPageByPos(TInt64 aPos); |
146 TDynamicDirCachePage* FindPageByPos(TInt64 aPos); |
150 TDynamicDirCachePage* UpdateActivePageL(TInt64 aPos); |
147 TDynamicDirCachePage* UpdateActivePageL(TInt64 aPos); |
151 TDynamicDirCachePage* AllocateAndLockNewPage(/*TInt64 aStartMedPos*/); |
148 TDynamicDirCachePage* AllocateAndLockNewPage(TInt64 aStartMedPos); |
152 TUint8* LockPage(TDynamicDirCachePage* aPage); |
149 TUint8* LockPage(TDynamicDirCachePage* aPage); |
153 TInt UnlockPage(TDynamicDirCachePage* aPage); |
150 TInt UnlockPage(TDynamicDirCachePage* aPage); |
154 TInt DecommitPage(TDynamicDirCachePage* aPage); |
151 TInt DecommitPage(TDynamicDirCachePage* aPage); |
155 inline TInt64 CalcPageStartPos(TInt64 aPos) const; |
152 inline TInt64 CalcPageStartPos(TInt64 aPos) const; |
156 void CheckThresholds(); |
153 void CheckThresholds(); |
160 TInt AddFirstOntoQueue(TDynamicDirCachePage* aPage, TDynamicDirCachePage::TPageType aType); |
157 TInt AddFirstOntoQueue(TDynamicDirCachePage* aPage, TDynamicDirCachePage::TPageType aType); |
161 TInt LookupTblRemove(TInt64 aPagePos); |
158 TInt LookupTblRemove(TInt64 aPagePos); |
162 TInt LookupTblAdd(TDynamicDirCachePage* aPage); |
159 TInt LookupTblAdd(TDynamicDirCachePage* aPage); |
163 TDynamicDirCachePage* LookupTblFind(TInt64 aPos); |
160 TDynamicDirCachePage* LookupTblFind(TInt64 aPos); |
164 TInt ResetPagePos(TDynamicDirCachePage* aPage); |
161 TInt ResetPagePos(TDynamicDirCachePage* aPage); |
|
162 void MakePageLastLocked(TDynamicDirCachePage* aPage); |
165 void DoMakePageMRU(TInt64 aPos); |
163 void DoMakePageMRU(TInt64 aPos); |
166 void DoInvalidateCache(void); |
164 void DoInvalidateCache(void); |
167 |
165 |
168 private: |
166 private: |
169 TUint32 iPageSizeLog2; ///< Log2(cache page size or read granularity unit) |
167 TUint32 iPageSizeLog2; ///< Log2(cache page size or read granularity unit) |
177 TInt64 iCacheBasePos; ///< cache pages base position, used to align them at cluster size |
175 TInt64 iCacheBasePos; ///< cache pages base position, used to align them at cluster size |
178 |
176 |
179 TDriveInterface& iDrive; ///< reference to the driver for media access |
177 TDriveInterface& iDrive; ///< reference to the driver for media access |
180 TUint32 iCacheDisabled : 1; ///< if not 0 the cache is disabled totally and all reads and writes go via TDriveInterface directly |
178 TUint32 iCacheDisabled : 1; ///< if not 0 the cache is disabled totally and all reads and writes go via TDriveInterface directly |
181 |
179 |
182 TDynamicDirCachePage* iLastVisitedPage; ///< a pointer to the last visited page, we always keep it locked |
|
183 ///< to avoid excessive lock/unlock activities when we are scanning |
|
184 ///< a page on the UnlockedQueue |
|
185 |
180 |
186 // data structures for LRU page list |
181 // data structures for LRU page list |
187 TCachePageList iLockedQ; ///< the locked queue that manages all locked pages, limited by minimum page number |
182 TCachePageList iLockedQ; ///< the locked queue that manages all locked pages, limited by minimum page number |
188 TCachePageList iUnlockedQ; ///< the unlocked queue that manages all locked pages, limited by maximum page number - minimum page number |
183 TCachePageList iUnlockedQ; ///< the unlocked queue that manages all locked pages, limited by maximum page number - minimum page number |
189 TUint32 iLockedQCount; |
184 TUint32 iLockedQCount; |