connectivitylayer/isce/memmanager_dll/src/memmanager.cpp
changeset 9 8486d82aef45
parent 5 8ccc39f9d787
equal deleted inserted replaced
8:6295dc2169f3 9:8486d82aef45
   122         )
   122         )
   123     {
   123     {
   124     C_TRACE( ( _T( "DMemManager::PoolAllocateDfc aPtr 0x%x>" ), aPtr ) );
   124     C_TRACE( ( _T( "DMemManager::PoolAllocateDfc aPtr 0x%x>" ), aPtr ) );
   125             
   125             
   126     DMemManager& tmp = *reinterpret_cast<DMemManager*>( aPtr );
   126     DMemManager& tmp = *reinterpret_cast<DMemManager*>( aPtr );
   127     TRACE_ASSERT_ALWAYS;// See below TODO comment, needs a fix
   127     TRACE_ASSERT_ALWAYS;
   128     
   128     
   129     NKern::FMWait( tmp.iFastMutex );
   129     NKern::FMWait( tmp.iFastMutex );
   130     
   130     
   131     ASSERT_RESET_ALWAYS( ( tmp.iPoolCreateQueue.Count() > 0 ), ( EInvalidQueueCount | EDMemmanagerTraceId << KClassIdentifierShift ) );
   131     ASSERT_RESET_ALWAYS( ( tmp.iPoolCreateQueue.Count() > 0 ), ( EInvalidQueueCount | EDMemmanagerTraceId << KClassIdentifierShift ) );
   132     TInt index = tmp.iMemPond.Find( tmp.iPoolCreateQueue[0] );
   132     TInt index = tmp.iMemPond.Find( tmp.iPoolCreateQueue[0] );
   147         )
   147         )
   148     {
   148     {
   149     C_TRACE( ( _T( "DMemManager::PoolDeleteDfc aPtr 0x%x>" ), aPtr ) );
   149     C_TRACE( ( _T( "DMemManager::PoolDeleteDfc aPtr 0x%x>" ), aPtr ) );
   150             
   150             
   151     DMemManager& tmp = *reinterpret_cast<DMemManager*>( aPtr );
   151     DMemManager& tmp = *reinterpret_cast<DMemManager*>( aPtr );
   152     TRACE_ASSERT_ALWAYS; // See below TODO comment, needs a fix
   152     TRACE_ASSERT_ALWAYS; 
   153     NKern::FMWait( tmp.iFastMutex );
   153     NKern::FMWait( tmp.iFastMutex );
   154     
   154     
   155     ASSERT_RESET_ALWAYS( ( tmp.iPoolDeleteQueue.Count() > 0 ), ( EInvalidQueueCount | EDMemmanagerTraceId << KClassIdentifierShift ) );
   155     ASSERT_RESET_ALWAYS( ( tmp.iPoolDeleteQueue.Count() > 0 ), ( EInvalidQueueCount | EDMemmanagerTraceId << KClassIdentifierShift ) );
   156     delete tmp.iPoolDeleteQueue[0];
   156     delete tmp.iPoolDeleteQueue[0];
   157     tmp.iPoolDeleteQueue.Remove(0);
   157     tmp.iPoolDeleteQueue.Remove(0);
   256 /*
   256 /*
   257 * Allocate memory unit.
   257 * Allocate memory unit.
   258 */
   258 */
   259 TPtr8* DMemManager::DMemPool::Alloc( const TUint16 aSize )
   259 TPtr8* DMemManager::DMemPool::Alloc( const TUint16 aSize )
   260     {
   260     {
   261 // TODO : not when FM	  C_TRACE( ( _T( "DMemManager::DMemPool::Alloc>" ) ) );
   261 //  not when FM	  C_TRACE( ( _T( "DMemManager::DMemPool::Alloc>" ) ) );
   262 	  
   262 	  
   263 	  ASSERT_RESET_ALWAYS( (iMemoryArea || iFreeMemBlock), ( EMemBlockAllocationFailed | EDMemmanagerTraceId << KClassIdentifierShift ) );
   263 	  ASSERT_RESET_ALWAYS( (iMemoryArea || iFreeMemBlock), ( EMemBlockAllocationFailed | EDMemmanagerTraceId << KClassIdentifierShift ) );
   264     
   264     
   265     struct sUnit *pCurUnit = iFreeMemBlock;
   265     struct sUnit *pCurUnit = iFreeMemBlock;
   266 
   266 
   280 
   280 
   281     iAllocatedMemBlock = pCurUnit;
   281     iAllocatedMemBlock = pCurUnit;
   282     
   282     
   283     iBlockUsage++;
   283     iBlockUsage++;
   284    
   284    
   285 // TODO : not when FM	  C_TRACE( ( _T( "DMemManager::DMemPool::Alloc<" ) ) );
   285 //  not when FM	  C_TRACE( ( _T( "DMemManager::DMemPool::Alloc<" ) ) );
   286     return iAllocatedMemBlock->iMemPtr;
   286     return iAllocatedMemBlock->iMemPtr;
   287     }
   287     }
   288 
   288 
   289 
   289 
   290 /*
   290 /*
   291 * Free memory unit.
   291 * Free memory unit.
   292 */
   292 */
   293 TBool DMemManager::DMemPool::Free( const TUint8* aBlockAddress )
   293 TBool DMemManager::DMemPool::Free( const TUint8* aBlockAddress )
   294     {
   294     {
   295 // TODO : not when FM    C_TRACE( ( _T( "DMemManager::DMemPool::Free>" ) ) );
   295 //  not when FM    C_TRACE( ( _T( "DMemManager::DMemPool::Free>" ) ) );
   296 	    
   296 	    
   297     struct sUnit *pCurUnit = (struct sUnit *)(aBlockAddress - sizeof(struct sUnit) );
   297     struct sUnit *pCurUnit = (struct sUnit *)(aBlockAddress - sizeof(struct sUnit) );
   298 
   298 
   299     iAllocatedMemBlock = pCurUnit->iNext;
   299     iAllocatedMemBlock = pCurUnit->iNext;
   300         
   300         
   312 
   312 
   313     iFreeMemBlock = pCurUnit;
   313     iFreeMemBlock = pCurUnit;
   314     iFreeMemBlock->iMemPtr->Zero();
   314     iFreeMemBlock->iMemPtr->Zero();
   315     iBlockUsage--;
   315     iBlockUsage--;
   316     
   316     
   317 // TODO : not when FM    C_TRACE( ( _T( "DMemManager::DMemPool::Free<" ) ) );
   317 //  not when FM    C_TRACE( ( _T( "DMemManager::DMemPool::Free<" ) ) );
   318 
   318 
   319     //If empty & ready to be deleted
   319     //If empty & ready to be deleted
   320     return ( iCopyPoolInUse && iBlockUsage == 0 ) ? ETrue : EFalse; 
   320     return ( iCopyPoolInUse && iBlockUsage == 0 ) ? ETrue : EFalse; 
   321  
   321  
   322     }
   322     }
   364     C_TRACE( ( _T( "MemApi::DeallocBlock aBlock 0x%x>" ), &aBlock ) );
   364     C_TRACE( ( _T( "MemApi::DeallocBlock aBlock 0x%x>" ), &aBlock ) );
   365     
   365     
   366     __ASSERT_NO_FAST_MUTEX;
   366     __ASSERT_NO_FAST_MUTEX;
   367     
   367     
   368     ASSERT_THREAD_CONTEXT_ALWAYS( ( EDeallocNotThreadContext | EDMemmanagerTraceId << KClassIdentifierShift ) );
   368     ASSERT_THREAD_CONTEXT_ALWAYS( ( EDeallocNotThreadContext | EDMemmanagerTraceId << KClassIdentifierShift ) );
   369     
   369     aBlock.FillZ( aBlock.MaxLength() );
       
   370     aBlock.SetLength(0);
   370     TBool removePool = EFalse;
   371     TBool removePool = EFalse;
   371     NKern::FMWait( DMemManager::iThisptr->iFastMutex );
   372     NKern::FMWait( DMemManager::iThisptr->iFastMutex );
   372     
   373     
   373     for( TUint8 i( 0 ); i < DMemManager::iThisptr->iMemPond.Count(); ++i )
   374     for( TUint8 i( 0 ); i < DMemManager::iThisptr->iMemPond.Count(); ++i )
   374         {
   375         {