commsfwutils/commsbufs/version1/mbufmgr/INC/MBufPoolChain.h
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 /**
       
     2 * Copyright (c) 2007-2009 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:
       
    15 * RMBufPoolChain decleration
       
    16 * 
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 /**
       
    23  @file
       
    24  @internalTechnology
       
    25 */
       
    26 
       
    27 #ifndef MBUF_POOL_CHAIN_H
       
    28 #define MBUF_POOL_CHAIN_H
       
    29 
       
    30 #include <e32def.h>     // for std types
       
    31 
       
    32 // forward decleration(s) to avoid circular dependency by including this file
       
    33 // - this is a symptom of multiple class declerations within the same header file
       
    34 //   eg. es_mbman.h required for CMBufPool, but also contains CMBufManager which inturn requires RMBufPoolChain defined in this file!
       
    35 class RMBufPoolChain;
       
    36 #include <es_mbman.h>       // for CMBufPool
       
    37 
       
    38 
       
    39 // this class is internal to MBM, but alas this can't be enforced by C++ (except by not exporting its header file)
       
    40 class RMBufPoolChain
       
    41 	{
       
    42 	friend class CMBufPoolManager;	// to allow access to private members
       
    43    
       
    44 	RMBufPoolChain(TInt aMBufSize, CMBufPoolManager& aMBufPoolManager); // to be used only in searching for existing poolchain
       
    45 	RMBufPoolChain(TInt aMBufSize, TInt aInitialAllocation, TInt aMinGrowth, TInt aHighGrowthThresholdPercentage, CMBufPoolManager& aMBufPoolManager);
       
    46 
       
    47 	void OpenL();
       
    48 	void Close();
       
    49 	
       
    50 public:	
       
    51 	
       
    52 	TInt GrowthSize(TInt aSize);
       
    53 	void ExtendFreeList(CMBufPool* aPool);  // assumed that the caller has already acquired the lock, refer comments within the definition
       
    54 	
       
    55 	TInt Alloc(RMBufQ& aList, TInt aSize, TBool aIsAllocPool);
       
    56 	static TInt Compare(const TInt* aMBufSize, const RMBufPoolChain& aRHSPoolChain);
       
    57 	static TInt Compare(const RMBufPoolChain& aLHSPoolChain, const RMBufPoolChain& aRHSPoolChain);
       
    58 	CMBufPoolManager& MBufPoolManager();
       
    59 	
       
    60 private:
       
    61 
       
    62 	RWorkerLock iLockFreeList;				// lock for free list
       
    63     TInt iLenFree;					// number of bytes free within the pool chain
       
    64     TInt iLenTotal;				// number of bytes allocated (free + used) within the pool chain
       
    65     RMBufQ iFreeMBufs;				// free list of mbufs ready to be consumed, use of plural naming implies the queue (hence the name isn't appended)
       
    66     TDblQue<CMBufPool> iPools;
       
    67 
       
    68    	const TInt iMBufSize;          // size (in bytes) of contained mbufs, also stored within mbuf but kept here for encapsulation & ease of reference
       
    69     const TInt iInitialAllocation; // initial allocation size in num of MBufs (not bytes)
       
    70     TInt iMinGrowth;  				// minimum (automatic) incremental allocation in num of MBufs (not bytes) - actual allocate may be larger (refer )
       
    71     TInt iGrowthThreshold; 		// if the num of free mbufs is <= this value, then a a new pool is automatically allocated
       
    72 
       
    73 	TBool iSignalled;				// background growth in progress
       
    74 	TInt iNumMBufsToAdd;			// background growth
       
    75 	TBool iNoMoreSpace;				// last background growth failed
       
    76 	TInt iLastGrowth;				// last attempted growth
       
    77 	TInt iMaxGrowthAttempt;			// largest growth attempt
       
    78 
       
    79 	TInt iDbgPoolLimit;				// limit size of pool chain
       
    80 	
       
    81 	CMBufPoolManager& iMBufPoolManager;
       
    82 	};
       
    83 
       
    84 #endif  // MBUF_POOL_CHAIN_H