sipxmedialib  Version 3.3
MpBufPool.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2012 SIPez LLC. All rights reserved.
3 //
4 // Copyright (C) 2006 SIPfoundry Inc.
5 // Licensed by SIPfoundry under the LGPL license.
6 //
7 // $$
9 
10 #ifndef _INCLUDED_MPBUFPOOL_H // [
11 #define _INCLUDED_MPBUFPOOL_H
12 
13 // SYSTEM INCLUDES
14 // APPLICATION INCLUDES
15 #include <os/OsMutex.h>
16 #include <utl/UtlString.h>
17 
18 // DEFINES
19 // MACROS
20 // EXTERNAL FUNCTIONS
21 // EXTERNAL VARIABLES
22 // CONSTANTS
23 // STRUCTS
24 // TYPEDEFS
25 
26 struct MpBuf;
27 struct MpBufList;
28 class MpFlowGraphBase;
29 class UtlString;
30 
32 class MpBufPool {
33 
34 /* //////////////////////////// PUBLIC //////////////////////////////////// */
35 public:
36 /* ============================ CREATORS ================================== */
38 
39 
41  MpBufPool(unsigned blockSize, unsigned numBlocks, const UtlString& poolName);
42 
44  virtual
45  ~MpBufPool();
46 
48 
49 /* ============================ MANIPULATORS ============================== */
51 
52 
54  MpBuf *getBuffer();
59  void releaseBuffer(MpBuf *pBuffer);
61 
63 
64 /* ============================ ACCESSORS ================================= */
66 
67 
69  unsigned getBlockSize() const {return mBlockSize;};
70 
72  unsigned getNumBlocks() const {return mNumBlocks;};
73 
75  int getBufferNumber(MpBuf *pBuf) const;
76 
78  int getFreeBufferCount();
79 
81  int scanBufPool(MpFlowGraphBase *pFG);
82 
85 
87  const UtlString& getName();
88 
90 
91 /* ============================ INQUIRY =================================== */
93 
94 
96 
97 /* //////////////////////////// PROTECTED ///////////////////////////////// */
98 protected:
99 
102 
104  char *getNextBlock(char *pBlock) {return pBlock + mBlockSpan;}
105 
106  void appendFreeList(MpBuf *pBuf);
107 
108  UtlString mPoolName;
109  unsigned mBlockSize;
110  unsigned mBlockSpan;
111  unsigned mNumBlocks;
112  unsigned mPoolBytes;
113  char *mpPoolData;
116  OsMutex mMutex;
118 
119 /* //////////////////////////// PRIVATE /////////////////////////////////// */
120 private:
121  unsigned mNumGets;
122  unsigned mNumFrees;
123  unsigned mNumFree;
124  unsigned mMinFree;
125 
126 };
127 
128 
129 #endif // _INCLUDED_MPBUFPOOL_H ]
MpBufList * mpFreeList
Definition: MpBufPool.h:115
unsigned mNumGets
Definition: MpBufPool.h:121
unsigned mNumFree
For statistics.
Definition: MpBufPool.h:123
unsigned mBlockSize
Requested size of each block in pool (in bytes).
Definition: MpBufPool.h:109
int scanBufPool(MpFlowGraphBase *pFG)
Scan for orphan buffers.
Definition: MpBufPool.cpp:235
unsigned mNumBlocks
Number of blocks in pool.
Definition: MpBufPool.h:111
unsigned getBlockSize() const
Return size of the one block in the pool (in bytes).
Definition: MpBufPool.h:69
unsigned mBlockSpan
Actual size of each block. >= mBlockSize for alignment.
Definition: MpBufPool.h:110
Class for internal MpBufPool use.
Definition: MpBufPool.cpp:52
int getBufferNumber(MpBuf *pBuf) const
Return number of the buffer in the pool. Use this for debug output.
Definition: MpBufPool.cpp:218
char * mpPoolData
Definition: MpBufPool.h:113
Flow graph for coordinating the execution of media processing resources.
Definition: MpFlowGraphBase.h:91
int getFreeBufferCount()
Return the number of free buffers.
Definition: MpBufPool.cpp:223
OsMutex mMutex
Mutex to avoid concurrent access to the pool.
Definition: MpBufPool.h:117
UtlString mPoolName
label or name for debug
Definition: MpBufPool.h:108
void releaseBuffer(MpBuf *pBuffer)
Bring this buffer back to pool.
Definition: MpBufPool.cpp:193
MpBufPool(unsigned blockSize, unsigned numBlocks, const UtlString &poolName)
Creates pool with numBlocks in it. Each block have size blockSize.
Definition: MpBufPool.cpp:93
int profileFlowgraphPoolUsage()
Syslog a histigram of buffers used by flowgraph.
Definition: MpBufPool.cpp:253
MpBuf * getBuffer()
Get free block from pool.
Definition: MpBufPool.cpp:150
void * getPoolDataEnd()
Return pointer to the byte after end of the pool data.
Definition: MpBufPool.h:101
unsigned getNumBlocks() const
Return number of blocks in the pool.
Definition: MpBufPool.h:72
const UtlString & getName()
Get the name label for this pool.
Definition: MpBufPool.cpp:300
char * getNextBlock(char *pBlock)
Return pointer to the block, next to this.
Definition: MpBufPool.h:104
unsigned mNumFrees
For statistics.
Definition: MpBufPool.h:122
virtual ~MpBufPool()
Destroys pool.
Definition: MpBufPool.cpp:130
Base class for all media buffers.
Definition: MpBuf.h:74
unsigned mMinFree
For statistics.
Definition: MpBufPool.h:124
void appendFreeList(MpBuf *pBuf)
Definition: MpBufPool.cpp:310
Pool of buffers.
Definition: MpBufPool.h:32
unsigned mPoolBytes
Size of all pool in bytes.
Definition: MpBufPool.h:112