userlibandfileserver/fileserver/sfat32/sl_dir_cache.h
changeset 33 0173bcd7697c
parent 15 4122176ea935
child 62 4a8fed1c0ef6
equal deleted inserted replaced
31:56f325a607ea 33:0173bcd7697c
    41 	enum TPageType
    41 	enum TPageType
    42 		{
    42 		{
    43 		EUnknown,
    43 		EUnknown,
    44 		ELocked,
    44 		ELocked,
    45 		EUnlocked,
    45 		EUnlocked,
    46 		EActivePage,
       
    47 		};
    46 		};
    48 
    47 
    49 public:
    48 public:
    50 	~TDynamicDirCachePage();
    49 	~TDynamicDirCachePage();
    51 	static TDynamicDirCachePage* NewL(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr);
    50 	static TDynamicDirCachePage* NewL(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr);
   113 */
   112 */
   114 class CDynamicDirCache : public CBase, public MWTCacheInterface
   113 class CDynamicDirCache : public CBase, public MWTCacheInterface
   115     {
   114     {
   116 public:
   115 public:
   117 	~CDynamicDirCache();
   116 	~CDynamicDirCache();
   118 	static CDynamicDirCache* NewL(TFatDriveInterface& aDrive, TUint32 aMinPageNum, TUint32 aMaxPageNum, TUint32 aPageSizeLog2, const TDesC& aClientName);
   117 	static CDynamicDirCache* NewL(TDriveInterface& aDrive, TUint32 aMinPageNum, TUint32 aMaxPageNum, TUint32 aPageSizeLog2, const TDesC& aClientName);
   119 
   118 
   120 	//-- overloads from the base class
   119 	//-- overloads from the base class
   121 	void    ReadL (TInt64 aPos, TInt aLength, TDes8& aDes);
   120 	void    ReadL (TInt64 aPos, TInt aLength, TDes8& aDes);
   122 	void    WriteL(TInt64 aPos, const TDesC8& aDes);
   121 	void    WriteL(TInt64 aPos, const TDesC8& aDes);
   123 	void    InvalidateCache(void);
   122 	void    InvalidateCache(void);
   135     // Debugging functions
   134     // Debugging functions
   136 	void Dump();
   135 	void Dump();
   137 	void Info() const;
   136 	void Info() const;
   138 
   137 
   139 protected:
   138 protected:
   140 	CDynamicDirCache(TFatDriveInterface& aDrive, TUint32 aMinSizeInBytes, TUint32 aMaxSizeInBytes, TUint32 aPageSizeInBytesLog2);
   139 	CDynamicDirCache(TDriveInterface& aDrive, TUint32 aMinSizeInBytes, TUint32 aMaxSizeInBytes, TUint32 aPageSizeInBytesLog2);
   141 	void ConstructL(const TDesC& aClientName);
   140 	void ConstructL(const TDesC& aClientName);
   142 
   141 
   143 	void ReadDataFromSinglePageL(TInt64 aPos, TInt aLength, TDes8& aDes);
   142 	void ReadDataFromSinglePageL(TInt64 aPos, TInt aLength, TDes8& aDes);
   144 	void WriteDataOntoSinglePageL(TInt64 aPos, const TUint8* aData, TUint32 aDataLen);
   143 	void WriteDataOntoSinglePageL(TInt64 aPos, const TUint8* aData, TUint32 aDataLen);
   145 	TDynamicDirCachePage* FindPageByPos(TInt64 aPos);
   144 	TDynamicDirCachePage* FindPageByPos(TInt64 aPos);
   157 	TInt LookupTblRemove(TInt64 aPagePos);
   156 	TInt LookupTblRemove(TInt64 aPagePos);
   158 	TInt LookupTblAdd(TDynamicDirCachePage* aPage);
   157 	TInt LookupTblAdd(TDynamicDirCachePage* aPage);
   159 	TDynamicDirCachePage* LookupTblFind(TInt64 aPos);
   158 	TDynamicDirCachePage* LookupTblFind(TInt64 aPos);
   160 	TInt ResetPagePos(TDynamicDirCachePage* aPage);
   159 	TInt ResetPagePos(TDynamicDirCachePage* aPage);
   161 	void MakePageLastLocked(TDynamicDirCachePage* aPage);
   160 	void MakePageLastLocked(TDynamicDirCachePage* aPage);
       
   161 	void DoMakePageMRU(TInt64 aPos);
       
   162 	void DoInvalidateCache(void);
   162 	
   163 	
   163 private:
   164 private:
   164 	TUint32				iPageSizeLog2;		///< log2 value of cache pages size in bytes
   165 	TUint32				iPageSizeLog2;		///< log2 value of cache pages size in bytes
   165 	TUint32				iMinCacheSizeInBytes;	///< minimum cache data size
   166 	TUint32				iMinCacheSizeInBytes;	///< minimum cache data size
   166 	TUint32				iMaxCacheSizeInBytes;	///< maximum cache data size
   167 	TUint32				iMaxCacheSizeInBytes;	///< maximum cache data size
   167 	TUint32				iMinSizeInPages;	///< minimum cache page number
   168 	TUint32				iMinSizeInPages;	///< minimum cache page number
   168 	TUint32				iMaxSizeInPages;	///< maximum cache page number
   169 	TUint32				iMaxSizeInPages;	///< maximum cache page number
   169 	TUint32             iPageSizeInBytes;	///< cache page size in bytes
   170 	TUint32             iPageSizeInBytes;	///< cache page size in bytes
   170 	TInt64              iCacheBasePos; 		///< cache pages base position, used to align them at cluster size
   171 	TInt64              iCacheBasePos; 		///< cache pages base position, used to align them at cluster size
   171 
   172 
   172 	TFatDriveInterface& iDrive;        		///< reference to the driver for media access
   173 	TDriveInterface&    iDrive;        		///< reference to the driver for media access
   173 	TUint32             iCacheDisabled : 1; ///< if not 0 the cache is disabled totally and all reads and writes go via TFatDriveInterface directly
   174 	TUint32             iCacheDisabled : 1; ///< if not 0 the cache is disabled totally and all reads and writes go via TDriveInterface directly
   174 
   175 
   175 	TDynamicDirCachePage* 	iActivePage;	///< a unique page in cache, used to read new page before make it MRU or have it replaced
       
   176 	
   176 	
   177 	// data structures for LRU page list	
   177 	// data structures for LRU page list	
   178 	TCachePageList 	iLockedQ;				///< the locked queue that manages all locked pages, limited by minimum page number
   178 	TCachePageList 	iLockedQ;				///< the locked queue that manages all locked pages, limited by minimum page number
   179 	TCachePageList 	iUnlockedQ;				///< the unlocked queue that manages all locked pages, limited by maximum page number - minimum page number
   179 	TCachePageList 	iUnlockedQ;				///< the unlocked queue that manages all locked pages, limited by maximum page number - minimum page number
   180 	TUint32			iLockedQCount;
   180 	TUint32			iLockedQCount;
   184 	THashFunction32<TLookupEntry> 	iHashFunction;
   184 	THashFunction32<TLookupEntry> 	iHashFunction;
   185 	TIdentityRelation<TLookupEntry>	iIdentityFunction;
   185 	TIdentityRelation<TLookupEntry>	iIdentityFunction;
   186 	RHashSet<TLookupEntry> 			iLookupTable;	///< a lookup table that used to speed up page look up
   186 	RHashSet<TLookupEntry> 			iLookupTable;	///< a lookup table that used to speed up page look up
   187 
   187 
   188 	CCacheMemoryClient*	iCacheMemoryClient;	///< interface to cache memory manager
   188 	CCacheMemoryClient*	iCacheMemoryClient;	///< interface to cache memory manager
       
   189 	TUint32 iPermanentlyAllocatedPageCount;	///< count of pages in locked queue that are never unlocked
       
   190 
   189     };
   191     };
   190 
   192 
   191 #include"sl_dir_cache.inl"
   193 #include"sl_dir_cache.inl"
   192 
   194 
   193 #endif //SL_DIR_CACHE_H
   195 #endif //SL_DIR_CACHE_H