userlibandfileserver/fileserver/sfile/sf_file_cache.cpp
branchRCL_3
changeset 43 c1f20ce4abcf
parent 41 0ffb4e86fcc9
child 44 3e88ff8f41d5
--- a/userlibandfileserver/fileserver/sfile/sf_file_cache.cpp	Thu Aug 19 11:14:22 2010 +0300
+++ b/userlibandfileserver/fileserver/sfile/sf_file_cache.cpp	Tue Aug 31 16:34:26 2010 +0300
@@ -32,6 +32,10 @@
 #include "sf_cache_client.h"
 #include "sf_file_cache_defs.h"
 
+#ifdef OST_TRACE_COMPILER_IN_USE
+#include "sf_file_cacheTraces.h"
+#endif
+
 
 // disables flushing of stale cachelines before each write
 #define LAZY_WRITE
@@ -80,6 +84,10 @@
 
 const TInt KMinSequentialReadsBeforeReadAhead = 3;
 
+#ifdef DOUBLE_BUFFERED_WRITING
+const TInt KMinSequentialAppendsBeforeFlush = 3;
+#endif
+
 //************************************
 // CFileCache
 //************************************
@@ -1163,6 +1171,18 @@
 					currentPos = iSize64;
 				iInitialSize = iSize64;
 
+
+#ifdef DOUBLE_BUFFERED_WRITING
+				// count the number of sequential write-appends
+				if (currentOperation->iClientRequest)
+					{
+					if (currentPos == iSize64)
+						iSequentialAppends++;
+					else
+						iSequentialAppends = 0;
+					}
+#endif // DOUBLE_BUFFERED_WRITING
+
 				// if EFileWriteDirectIO OR 
 				// (caching writes and requested write len > size of the cache), 
 				// flush the write cache
@@ -1271,6 +1291,13 @@
 						lastError = r;
 					}
 #endif
+#ifdef DOUBLE_BUFFERED_WRITING
+				if (cachingWrites && lastError == KErrNone && 
+					iSequentialAppends >= KMinSequentialAppendsBeforeFlush && iCacheClient->LockedSegmentsHalfUsed())
+					{
+					DoFlushDirty(aNewRequest, &aMsgRequest, EFlushHalf);
+					}
+#endif
 				// if no cacheline found & write caching is enabled, allocate a new cacheline
 				if (cachingWrites && addr == NULL && lastError == KErrNone)
 					{
@@ -1603,17 +1630,13 @@
 
 void CFileCache::PropagateFlushErrorToAllFileShares()
 	{
-	FileShares->Lock();
-	TInt count = FileShares->Count();
-	while(count--)
+	ASSERT(IsDriveThread());
+	TDblQueIter<CFileShare> fileShareIter(iFileCB->FileShareList());
+	CFileShare* pFileShare;
+	while ((pFileShare = fileShareIter++) != NULL)
 		{
-		CFileShare* share = (CFileShare*)(*FileShares)[count];
-		if (&share->File() == iFileCB)
-			{
-			share->iFlushError = iFlushError;
-			}
+		pFileShare->iFlushError = iFlushError;
 		}
-	FileShares->Unlock();
 	}
 
 /**
@@ -1815,7 +1838,7 @@
 
 #ifdef SETSIZE_BEFORE_WRITE	
 				TInt64 physicalFileSize = iFileCB->Size64();
-				if ( (!iDrive->IsRugged()) && ((pos + (TInt64) len) > physicalFileSize))
+				if ((pos + (TInt64) len) > physicalFileSize)
 					{
 					// Need to switch to drive thread before calling CFileCB::SetSizeL()
 					if (!IsDriveThread())
@@ -1933,6 +1956,12 @@
 					case EFlushSingle:
 						currentOperation->iState = EStEnd;
 						break;
+					case EFlushHalf:
+						if (iCacheClient->LockedSegmentsHalfUsed())
+							currentOperation->iState = EStWriteToDisk;
+						else
+							currentOperation->iState = EStEnd;
+						break;
 					case EFlushAll:
 						currentOperation->iState = EStWriteToDisk;
 						break;
@@ -2034,11 +2063,11 @@
 			// However if the write error is to the bootsector remounting will always fail because the boot
 			// sector will have changed and hence the disk is useless.
 			// 
-			TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBReMount, EF32TraceUidFileSys, DriveNumber());
+			OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBREMOUNT2, "drive %d", DriveNumber());
 
 			TInt remountSuccess = iDrive->ReMount(*iMount);
 
-			TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBReMountRet, EF32TraceUidFileSys, remountSuccess);
+			OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBREMOUNT2RET, "success %d", remountSuccess);
 			if (!remountSuccess)
 				continue;