userlibandfileserver/fileserver/sfile/sf_memory_client.cpp
branchanywhere
changeset 41 d32f34975bbf
parent 36 538db54a451d
child 62 4a8fed1c0ef6
child 90 947f0dc9f7a8
equal deleted inserted replaced
40:04a1b74efd48 41:d32f34975bbf
    32 
    32 
    33 CCacheMemoryClient::~CCacheMemoryClient()
    33 CCacheMemoryClient::~CCacheMemoryClient()
    34 	{
    34 	{
    35 	const TUint32 segCnt = iTouchedRegionFlag <= iReservedRegionMarkInSegs ? 
    35 	const TUint32 segCnt = iTouchedRegionFlag <= iReservedRegionMarkInSegs ? 
    36 										iReservedRegionMarkInSegs : iTouchedRegionFlag;
    36 										iReservedRegionMarkInSegs : iTouchedRegionFlag;
    37 	DecommitSegments(iBase, segCnt);
    37 	TInt r = DecommitSegments(iBase, segCnt);
       
    38 	if (r != KErrNone)  // this 'if() {}' is to remove build warnings
       
    39 	{
       
    40 	ASSERT(0);
       
    41 	}
    38 	iReusablePagePool.Close();
    42 	iReusablePagePool.Close();
    39 	delete iName;
    43 	delete iName;
    40 	}
    44 	}
    41 
    45 
    42 /**
    46 /**
    79 @param	aClientName	the unique identification of CCacheMemoryClient
    83 @param	aClientName	the unique identification of CCacheMemoryClient
    80 @param	aOffsetInBytes	the offset to the base position of CCacheMemoryManager it registered
    84 @param	aOffsetInBytes	the offset to the base position of CCacheMemoryManager it registered
    81 */
    85 */
    82 void CCacheMemoryClient::ConstructL(const TDesC& aClientName, TUint32 aOffsetInBytes)
    86 void CCacheMemoryClient::ConstructL(const TDesC& aClientName, TUint32 aOffsetInBytes)
    83 	{
    87 	{
       
    88     __PRINT4(_L("CCacheMemoryClient::ConstructL(%S, min=%d, max=%d, base=0x%X)"), &aClientName, iMinSizeInSegs, iMaxSizeInSegs, iBase);
    84 	iName = HBufC::NewMaxL(aClientName.Length());
    89 	iName = HBufC::NewMaxL(aClientName.Length());
    85 	*iName = aClientName;
    90 	*iName = aClientName;
    86 	iSegSizeInBytesLog2 = iManager.SegmentSizeInBytesLog2();
    91 	iSegSizeInBytesLog2 = iManager.SegmentSizeInBytesLog2();
    87 	iSegSizeInBytes = 1 << iSegSizeInBytesLog2;
    92 	iSegSizeInBytes = 1 << iSegSizeInBytesLog2;
    88 	iReusablePagePool.Close();
    93 	iReusablePagePool.Close();
    91 	iReservedRegionMarkInSegs = iMinSizeInSegs;
    96 	iReservedRegionMarkInSegs = iMinSizeInSegs;
    92 	TInt r = iManager.AllocateAndLockSegments(iBase, iReservedRegionMarkInSegs);
    97 	TInt r = iManager.AllocateAndLockSegments(iBase, iReservedRegionMarkInSegs);
    93 	ASSERT(r==KErrNone);
    98 	ASSERT(r==KErrNone);
    94 	User::LeaveIfError(r);
    99 	User::LeaveIfError(r);
    95 	iTouchedRegionFlag = 0;
   100 	iTouchedRegionFlag = 0;
    96 	__PRINT4(_L("CCacheMemoryClient::ConstructL(%S, min=%d, max=%d, base=0x%X)"), &aClientName, iMinSizeInSegs, iMaxSizeInSegs, iBase);
   101 	__PRINT(_L("CCacheMemoryClient::ConstructL() return 0"));
    97 	}
   102 	}
    98 
   103 
    99 /**
   104 /**
   100 Reset the client state, this is normally issued from the cache it connected with.
   105 Reset the client state, this is normally issued from the cache it connected with.
   101 For exmaple, a FAT volume is dismounted so the directory cache needs to be reset.
   106 For exmaple, a FAT volume is dismounted so the directory cache needs to be reset.
   107 */
   112 */
   108 EXPORT_C void CCacheMemoryClient::Reset()
   113 EXPORT_C void CCacheMemoryClient::Reset()
   109 	{
   114 	{
   110 	__PRINT3(_L("CCacheMemoryClient::Reset(%S, reserved=%d, touched=%d)"), iName, iReservedRegionMarkInSegs, iTouchedRegionFlag);
   115 	__PRINT3(_L("CCacheMemoryClient::Reset(%S, reserved=%d, touched=%d)"), iName, iReservedRegionMarkInSegs, iTouchedRegionFlag);
   111 	
   116 	
   112 	// in case that client user has incorrectly decommited reserved region (normally on destruction), 
   117 	// reset the cache memeory client to initial states: 
   113 	//	we should re-commit reserved region here to prepare the next connection.
   118 	//     1. all memory that have been 'touched' should be decommitted
   114 	TInt r = DecommitSegments(iBase, iReservedRegionMarkInSegs);
   119 	//     2. the reserved region of memory should be re-locked
   115 	if (r != KErrNone)	// this 'if() {}' is to remove build warnings in debug mode, same is below
   120 
   116 		{
   121 	// if we have touched more than reserved region of memory, we shall decommit all of them 
   117 		ASSERT(0);
       
   118 		}
       
   119 
       
   120 	r = iManager.AllocateAndLockSegments(iBase, iReservedRegionMarkInSegs);
       
   121 	if (r != KErrNone)
       
   122 		{
       
   123 		ASSERT(0);
       
   124 		}
       
   125 
       
   126 	// if we have touched more than reserved, we also need to make sure it's decommitted.
       
   127 	if (iTouchedRegionFlag > iReservedRegionMarkInSegs)
   122 	if (iTouchedRegionFlag > iReservedRegionMarkInSegs)
   128 		{
   123 	    {
   129 		TInt r = iManager.DecommitSegments(iBase + (iReservedRegionMarkInSegs << iSegSizeInBytesLog2), iTouchedRegionFlag - iReservedRegionMarkInSegs);
   124 	    TInt r = DecommitSegments(iBase, iTouchedRegionFlag);
   130 		if (r != KErrNone)
   125 	    if (r != KErrNone)  // this 'if() {}' is to remove build warnings in debug mode, same is below
   131 			{
   126 	        {
   132 			ASSERT(0);
   127 	        ASSERT(0);
   133 			}
   128 	        }
   134 		}
   129 	    }
   135 	
   130 	else   // otherwise we decommit the reserved region of memory only.
       
   131 	    {
       
   132 	    TInt r = DecommitSegments(iBase, iReservedRegionMarkInSegs);
       
   133 	    if (r != KErrNone)  // this 'if() {}' is to remove build warnings in debug mode, same is below
       
   134 	        {
       
   135 	        ASSERT(0);
       
   136 	        }
       
   137 	    }
       
   138 
       
   139     // re-lock the reserved region of memory
       
   140 	TInt r = iManager.AllocateAndLockSegments(iBase, iReservedRegionMarkInSegs);
       
   141     if (r != KErrNone)
       
   142         {
       
   143         ASSERT(0);
       
   144         }
       
   145 
   136 	iTouchedRegionFlag = 0;
   146 	iTouchedRegionFlag = 0;
   137 	iReusablePagePool.Close();
   147 	iReusablePagePool.Close();
   138 	iReusablePagePool.Reserve(iReservedRegionMarkInSegs);
   148 	iReusablePagePool.Reserve(iReservedRegionMarkInSegs);
   139 	}
   149 	}
   140 
   150 
   146 @internalTechnology
   156 @internalTechnology
   147 @released
   157 @released
   148 */
   158 */
   149 EXPORT_C TUint8* CCacheMemoryClient::AllocateAndLockSegments(TUint32 aSegmentCount)
   159 EXPORT_C TUint8* CCacheMemoryClient::AllocateAndLockSegments(TUint32 aSegmentCount)
   150 	{
   160 	{
   151 	__PRINT3(_L("CCacheMemoryClient::AllocateAndLockSegments(%S, reserved=%d, touched=%d)"), iName, iReservedRegionMarkInSegs, iTouchedRegionFlag);
   161 	__PRINT4(_L("CCacheMemoryClient::AllocateAndLockSegments(%S, segs=%d, reserved=%d, touched=%d)"), iName, aSegmentCount, iReservedRegionMarkInSegs, iTouchedRegionFlag);
   152 //	__PRINT2(_L("iBase = 0x%x, segcnt = %d"), iBase, aSegmentCount);
   162 //	__PRINT2(_L("iBase = 0x%x, segcnt = %d"), iBase, aSegmentCount);
   153     TUint8* addr = NULL;
   163     TUint8* addr = NULL;
   154     // if we are walking through the reserved region first time, we should
   164     // if we are walking through the reserved region first time, we should
   155     // make assumption that this area is locked already
   165     // make assumption that this area is locked already
   156     if (iTouchedRegionFlag + aSegmentCount <= iReservedRegionMarkInSegs)
   166     if (iTouchedRegionFlag + aSegmentCount <= iReservedRegionMarkInSegs)