mpx/commonframework/common/inc/mpxheapmanager.inl
changeset 0 a2952bb97e68
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Inline implementation of heap manager 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <mpxuser.h>
       
    19 
       
    20 // -----------------------------------------------------------------------------
       
    21 // Client handle
       
    22 // -----------------------------------------------------------------------------
       
    23 //
       
    24 inline TUint RMPXHeapManager::ClientHandle(TUint8* aBase,TInt aClientIndex)
       
    25     { 
       
    26     // We assume here that the chunk base address ends in 0x00 so we can put the client
       
    27     // index at this location, so we must make sure that is true, and that there are
       
    28     // no more clients than will fit, i.e. 0xff (255)
       
    29     // 
       
    30     MPX_ASSERT(aBase&&aClientIndex>=0&&aClientIndex<ENumClients);
       
    31     MPX_ASSERT(((TUint)aBase&0xff)==0);
       
    32     TUint h=(TUint)aBase|aClientIndex;
       
    33     MPX_ASSERT((h&0xff)==aClientIndex);
       
    34     MPX_ASSERT(reinterpret_cast<TUint8*>(h&0xffffff00)==aBase);
       
    35     return h; 
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // Client index
       
    40 // -----------------------------------------------------------------------------
       
    41 // 
       
    42 inline TInt RMPXHeapManager::ClientIndex(TUint aClientHandle)
       
    43     { 
       
    44     MPX_ASSERT(aClientHandle);
       
    45     return aClientHandle&0xff; 
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // Chunk Base
       
    50 // -----------------------------------------------------------------------------
       
    51 // 
       
    52 inline TUint8* RMPXHeapManager::ChunkBase(TUint aClientHandle)
       
    53     { 
       
    54     MPX_ASSERT(aClientHandle);
       
    55     return reinterpret_cast<TUint8*>(aClientHandle&0xffffff00); 
       
    56     }
       
    57     
       
    58 // -----------------------------------------------------------------------------
       
    59 // Absolute pointer to T (thread relative)
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 template<typename T>  
       
    63 inline T* RMPXHeapManager::Ptr(TUint aClientHandle,TInt aOffset)
       
    64     { 
       
    65     T* ptr=reinterpret_cast<T*>(ChunkBase(aClientHandle)+aOffset);
       
    66     MPX_ASSERT(aOffset==((TUint8*)ptr-ChunkBase(aClientHandle))); 
       
    67     return ptr; 
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // Relative offset from absolute pointer
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 inline TInt RMPXHeapManager::Offset(TUint aClientHandle,TAny* aPtr)
       
    75     { 
       
    76     TInt o=((TUint8*)aPtr-ChunkBase(aClientHandle));
       
    77     MPX_ASSERT(aPtr==reinterpret_cast<TAny*>(ChunkBase(aClientHandle)+o));
       
    78     return o; 
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // RMPXHeapManager::HeapManager
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 inline RMPXHeapManager& RMPXHeapManager::HeapManager(TUint aClientHandle)
       
    86     { return *Ptr<RMPXHeapManager>(aClientHandle); }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // Frees an offset on the chunk
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 inline TInt RMPXHeapManager::Free(TUint aClientHandle,TInt aOffset)
       
    93     {
       
    94     return Free(aClientHandle,Ptr<TAny>(aClientHandle,aOffset));
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // Allocate an object on the chunk
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 template<typename T> 
       
   102 inline T* RMPXHeapManager::Alloc(TUint aClientHandle)
       
   103     {
       
   104     T* obj=NULL;
       
   105     TAny* ptr=Alloc(aClientHandle,sizeof(T));
       
   106     if (ptr)
       
   107         {
       
   108         obj=new(ptr)T;
       
   109         }
       
   110     MPX_ASSERT_WORD_ALIGNED(obj);
       
   111     return obj;
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // Copy a buffer on the chunk
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 inline TInt RMPXHeapManager::Copy(TUint aClientHandle,TInt aSrcOffset,TInt aSize)
       
   119     {
       
   120     return Copy(aClientHandle,RMPXHeapManager::Ptr<TAny>(aClientHandle,aSrcOffset),aSize);
       
   121     }
       
   122 
       
   123 // End of file