userlibandfileserver/fileserver/sfat32/sl_dir_cache.h
changeset 201 43365a9b78a3
parent 102 ef2a444a7410
child 257 3e88ff8f41d5
equal deleted inserted replaced
200:73ea206103e6 201:43365a9b78a3
    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>
    30 
    31 
    31 //---------------------------------------------------------------------------------------------------------------------------------
    32 //---------------------------------------------------------------------------------------------------------------------------------
    32 class 	CDynamicDirCache;
    33 class 	CDynamicDirCache;
    33 
    34 
    34 
    35 
   130 	void 	MakePageMRU(TInt64 aPos);
   131 	void 	MakePageMRU(TInt64 aPos);
   131 	TUint32	PageSizeInBytesLog2() const;
   132 	TUint32	PageSizeInBytesLog2() const;
   132 	
   133 	
   133 	TUint32 PageSizeInSegs() const;
   134 	TUint32 PageSizeInSegs() const;
   134 
   135 
       
   136 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   135     // Debugging functions
   137     // Debugging functions
   136 	void Dump();
   138 	void Dump();
   137 	void Info() const;
   139 	void Info(TDirCacheInfo* aInfo) const;
       
   140 #endif //#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   138 
   141 
   139 protected:
   142 protected:
   140 	CDynamicDirCache(TDriveInterface& aDrive, TUint32 aMinSizeInBytes, TUint32 aMaxSizeInBytes, TUint32 aPageSizeInBytesLog2, TUint32 aWrGranularityLog2);
   143 	CDynamicDirCache(TDriveInterface& aDrive, TUint32 aMinSizeInBytes, TUint32 aMaxSizeInBytes, TUint32 aPageSizeInBytesLog2, TUint32 aWrGranularityLog2);
   141 	void ConstructL(const TDesC& aClientName);
   144 	void ConstructL(const TDesC& aClientName);
   142 
   145 
   143 	void ReadDataFromSinglePageL(TInt64 aPos, TInt aLength, TDes8& aDes);
   146 	void ReadDataFromSinglePageL(TInt64 aPos, TInt aLength, TDes8& aDes);
   144 	TDynamicDirCachePage* WriteDataOntoSinglePageL(TInt64 aPos, const TUint8* aData, TUint32 aDataLen);
   147 	TDynamicDirCachePage* WriteDataOntoSinglePageL(TInt64 aPos, const TUint8* aData, TUint32 aDataLen);
   145 
   148 
   146 	TDynamicDirCachePage* FindPageByPos(TInt64 aPos);
   149 	TDynamicDirCachePage* FindPageByPos(TInt64 aPos);
   147 	TDynamicDirCachePage* UpdateActivePageL(TInt64 aPos);
   150 	TDynamicDirCachePage* UpdateActivePageL(TInt64 aPos);
   148 	TDynamicDirCachePage* AllocateAndLockNewPage(TInt64 aStartMedPos);
   151 	TDynamicDirCachePage* AllocateAndLockNewPage(/*TInt64 aStartMedPos*/);
   149 	TUint8* LockPage(TDynamicDirCachePage* aPage);
   152 	TUint8* LockPage(TDynamicDirCachePage* aPage);
   150 	TInt 	UnlockPage(TDynamicDirCachePage* aPage);
   153 	TInt 	UnlockPage(TDynamicDirCachePage* aPage);
   151 	TInt 	DecommitPage(TDynamicDirCachePage* aPage);
   154 	TInt 	DecommitPage(TDynamicDirCachePage* aPage);
   152 	inline TInt64  CalcPageStartPos(TInt64 aPos) const;
   155 	inline TInt64  CalcPageStartPos(TInt64 aPos) const;
   153 	void CheckThresholds();
   156 	void CheckThresholds();
   157 	TInt AddFirstOntoQueue(TDynamicDirCachePage* aPage, TDynamicDirCachePage::TPageType aType);
   160 	TInt AddFirstOntoQueue(TDynamicDirCachePage* aPage, TDynamicDirCachePage::TPageType aType);
   158 	TInt LookupTblRemove(TInt64 aPagePos);
   161 	TInt LookupTblRemove(TInt64 aPagePos);
   159 	TInt LookupTblAdd(TDynamicDirCachePage* aPage);
   162 	TInt LookupTblAdd(TDynamicDirCachePage* aPage);
   160 	TDynamicDirCachePage* LookupTblFind(TInt64 aPos);
   163 	TDynamicDirCachePage* LookupTblFind(TInt64 aPos);
   161 	TInt ResetPagePos(TDynamicDirCachePage* aPage);
   164 	TInt ResetPagePos(TDynamicDirCachePage* aPage);
   162 	void MakePageLastLocked(TDynamicDirCachePage* aPage);
       
   163 	void DoMakePageMRU(TInt64 aPos);
   165 	void DoMakePageMRU(TInt64 aPos);
   164 	void DoInvalidateCache(void);
   166 	void DoInvalidateCache(void);
   165 	
   167 	
   166 private:
   168 private:
   167 	TUint32				iPageSizeLog2;		    ///< Log2(cache page size or read granularity unit) 
   169 	TUint32				iPageSizeLog2;		    ///< Log2(cache page size or read granularity unit) 
   175 	TInt64              iCacheBasePos; 		///< cache pages base position, used to align them at cluster size
   177 	TInt64              iCacheBasePos; 		///< cache pages base position, used to align them at cluster size
   176 
   178 
   177 	TDriveInterface&    iDrive;        		///< reference to the driver for media access
   179 	TDriveInterface&    iDrive;        		///< reference to the driver for media access
   178 	TUint32             iCacheDisabled : 1; ///< if not 0 the cache is disabled totally and all reads and writes go via TDriveInterface directly
   180 	TUint32             iCacheDisabled : 1; ///< if not 0 the cache is disabled totally and all reads and writes go via TDriveInterface directly
   179 
   181 
       
   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
   180 	
   185 	
   181 	// data structures for LRU page list	
   186 	// data structures for LRU page list	
   182 	TCachePageList 	iLockedQ;				///< the locked queue that manages all locked pages, limited by minimum page number
   187 	TCachePageList 	iLockedQ;				///< the locked queue that manages all locked pages, limited by minimum page number
   183 	TCachePageList 	iUnlockedQ;				///< the unlocked queue that manages all locked pages, limited by maximum page number - minimum page number
   188 	TCachePageList 	iUnlockedQ;				///< the unlocked queue that manages all locked pages, limited by maximum page number - minimum page number
   184 	TUint32			iLockedQCount;
   189 	TUint32			iLockedQCount;