157 |
157 |
158 |
158 |
159 // allocate as many permanently locked pages as there are threads - plus one |
159 // allocate as many permanently locked pages as there are threads - plus one |
160 // otherwise DoMakePageMRU() won't work properly with only one thread |
160 // otherwise DoMakePageMRU() won't work properly with only one thread |
161 //-- At present moment the size of TDrive thread pool is 1 (1 drive thread in a pool) |
161 //-- At present moment the size of TDrive thread pool is 1 (1 drive thread in a pool) |
162 iPermanentlyAllocatedPageCount = 1; |
162 const TUint KThreadCount = 1; |
|
163 iPermanentlyAllocatedPageCount = KThreadCount + 1; |
163 |
164 |
164 if (iPermanentlyAllocatedPageCount > iMinSizeInPages) |
165 if (iPermanentlyAllocatedPageCount > iMinSizeInPages) |
165 iMinSizeInPages = iPermanentlyAllocatedPageCount; |
166 iMinSizeInPages = iPermanentlyAllocatedPageCount; |
166 |
167 |
167 for (TUint n=0; n<iPermanentlyAllocatedPageCount; n++) |
168 for (TUint n=0; n<iPermanentlyAllocatedPageCount; n++) |
677 |
678 |
678 void CDynamicDirCache::DoMakePageMRU(TInt64 aPos) |
679 void CDynamicDirCache::DoMakePageMRU(TInt64 aPos) |
679 { |
680 { |
680 // __PRINT1(_L("MakePageMRU (%lx)"), aPos); |
681 // __PRINT1(_L("MakePageMRU (%lx)"), aPos); |
681 // __PRINT4(_L("Current Cache State: iLockedQCount=%d, iUnlockedQCount=%d, iLookupTbl=%d, iMaxSizeInPages=%d"), iLockedQCount, iUnlockedQCount, iLookupTable.Count(), iMaxSizeInPages); |
682 // __PRINT4(_L("Current Cache State: iLockedQCount=%d, iUnlockedQCount=%d, iLookupTbl=%d, iMaxSizeInPages=%d"), iLockedQCount, iUnlockedQCount, iLookupTable.Count(), iMaxSizeInPages); |
|
683 // check there are at least two locked pages |
|
684 ASSERT(iLockedQCount > 1); |
|
685 |
682 // check the MRU page first, if it is already the MRU page, we can return immediately |
686 // check the MRU page first, if it is already the MRU page, we can return immediately |
683 TInt64 pageStartMedPos = CalcPageStartPos(aPos); |
687 TInt64 pageStartMedPos = CalcPageStartPos(aPos); |
684 if (!iLockedQ.IsEmpty()) |
688 if (!iLockedQ.IsEmpty()) |
685 { |
689 { |
686 if (iLockedQ.First()->StartPos() == pageStartMedPos) |
690 if (iLockedQ.First()->StartPos() == pageStartMedPos) |
947 /** |
951 /** |
948 Dump cache content, only enabled in debug mode. |
952 Dump cache content, only enabled in debug mode. |
949 @see CDynamicDirCache::Control() |
953 @see CDynamicDirCache::Control() |
950 */ |
954 */ |
951 void CDynamicDirCache::Dump() |
955 void CDynamicDirCache::Dump() |
952 { |
956 { |
953 __PRINT(_L("======== CDynamicDirCache::Dump =========")); |
957 __PRINT(_L("======== CDynamicDirCache::Dump =========")); |
954 if (!iLockedQ.IsEmpty()) |
958 if (!iLockedQ.IsEmpty()) |
955 { |
959 { |
956 TDblQueIter<TDynamicDirCachePage> q(iLockedQ); |
960 TDblQueIter<TDynamicDirCachePage> q(iLockedQ); |
957 q.SetToFirst(); |
961 q.SetToFirst(); |
958 TInt i = 0; |
962 TInt i = 0; |
959 while((TDynamicDirCachePage*)q) |
963 while((TDynamicDirCachePage*)q) |
960 { |
964 { |
961 TDynamicDirCachePage* pP = q++; |
965 TDynamicDirCachePage* pP = q++; |
962 __PRINT5(_L("=== CDynamicDirCache::iLockedQ\t[%4d](pos=%lx, locked=%d, valid=%d, size=%u)"), i++, pP->StartPos(), pP->IsLocked(), pP->IsValid(), pP->PageSizeInBytes()); |
966 __PRINT5(_L("=== CDynamicDirCache::iLockedQ [%4d](pos=%lx, locked=%d, valid=%d, size=%u)"), i++, pP->StartPos(), pP->IsLocked(), pP->IsValid(), pP->PageSizeInBytes()); |
963 } |
967 } |
964 } |
968 } |
965 if (!iUnlockedQ.IsEmpty()) |
969 __PRINT(_L("=== CDynamicDirCache:: --------------------")); |
966 { |
970 |
967 TDblQueIter<TDynamicDirCachePage> q(iUnlockedQ); |
971 if (!iUnlockedQ.IsEmpty()) |
968 q.SetToFirst(); |
972 { |
969 TInt i = 0; |
973 TDblQueIter<TDynamicDirCachePage> q(iUnlockedQ); |
970 while((TDynamicDirCachePage*)q) |
974 q.SetToFirst(); |
971 { |
975 TInt i = 0; |
972 TDynamicDirCachePage* pP = q++; |
976 while((TDynamicDirCachePage*)q) |
973 __PRINT5(_L("=== CDynamicDirCache::iUnlockedQ\t[%4d](pos=%lx, locked=%d, valid=%d, size=%u)"), i++, pP->StartPos(), pP->IsLocked(), pP->IsValid(), pP->PageSizeInBytes()); |
977 { |
974 } |
978 TDynamicDirCachePage* pP = q++; |
975 } |
979 __PRINT5(_L("=== CDynamicDirCache::iUnlockedQ [%4d](pos=%lx, locked=%d, valid=%d, size=%u)"), i++, pP->StartPos(), pP->IsLocked(), pP->IsValid(), pP->PageSizeInBytes()); |
976 |
980 } |
977 if (iLookupTable.Count()) |
981 } |
978 { |
982 __PRINT(_L("=== CDynamicDirCache:: --------------------")); |
979 TInt i = 0; |
983 |
980 THashSetIter<TLookupEntry> iter(iLookupTable); |
984 if (iLookupTable.Count()) |
981 TLookupEntry* pEntry; |
985 { |
982 pEntry = (TLookupEntry*) iter.Next(); |
986 TInt i = 0; |
983 while(pEntry) |
987 THashSetIter<TLookupEntry> iter(iLookupTable); |
984 { |
988 TLookupEntry* pEntry; |
985 TDynamicDirCachePage* pP = pEntry->iPage; |
989 pEntry = (TLookupEntry*) iter.Next(); |
986 __PRINT5(_L("=== CDynamicDirCache::iLookupTable\t[%4d](pos=%lx, locked=%d, valid=%d, size=%u)"), i++, pP->StartPos(), pP->IsLocked(), pP->IsValid(), pP->PageSizeInBytes()); |
990 while(pEntry) |
987 pEntry = (TLookupEntry*) iter.Next(); |
991 { |
988 }; |
992 TDynamicDirCachePage* pP = pEntry->iPage; |
989 } |
993 __PRINT5(_L("=== CDynamicDirCache::iLookupTable [%4d](pos=%lx, locked=%d, valid=%d, size=%u)"), i++, pP->StartPos(), pP->IsLocked(), pP->IsValid(), pP->PageSizeInBytes()); |
990 __PRINT(_L("===========================================\n")); |
994 pEntry = (TLookupEntry*) iter.Next(); |
991 } |
995 }; |
|
996 } |
|
997 __PRINT(_L("===========================================\n")); |
|
998 } |
992 #endif //_DEBUG |
999 #endif //_DEBUG |
993 |
1000 |
994 /** |
1001 /** |
995 Lock an unlocked page, or do nothing if the page is already locked. |
1002 Lock an unlocked page, or do nothing if the page is already locked. |
996 @return TUint8* pointer of the page to be locked, if locking is successful, otherwise return NULL. |
1003 @return TUint8* pointer of the page to be locked, if locking is successful, otherwise return NULL. |