sipxportlib  Version 3.3
UtlChainPool.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2007 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2007 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 #ifndef UtlChainPool_h__
12 #define UtlChainPool_h__
13 
14 // SYSTEM INCLUDES
15 // APPLICATION INCLUDES
16 #include "utl/UtlLink.h"
17 
18 // DEFINES
19 // MACROS
20 // EXTERNAL FUNCTIONS
21 // EXTERNAL VARIABLES
22 // CONSTANTS
23 // FORWARD DECLARATIONS
24 // STRUCTS
25 // TYPEDEFS
26 
28 
38 {
39 /* //////////////////////////// PUBLIC //////////////////////////////////// */
40 public:
41 
42 /* //////////////////////////// PROTECTED ///////////////////////////////// */
43 protected:
44  friend class UtlLink;
45  friend class UtlPair;
46  friend class UtlInit;
47 
49  typedef void allocator(size_t blocksize,
50  UtlChain* blockList,
51  UtlChain* pool
52  );
61  UtlChainPool(allocator* blockAllocator, size_t blockSize);
63 
65  UtlChain* get();
66 
68  void release(UtlChain* freeChain);
69 
71 
75  size_t totalAllocated()
76  {
77  return mAllocations * (mBlockSize-1); // one per block is overhead
78  }
79 
80 /* //////////////////////////// PRIVATE /////////////////////////////////// */
81 private:
82 
84  ~UtlChainPool();
85 
86  OsBSem mLock;
87  size_t mBlockSize;
88  size_t mAllocations;
89  allocator* mAllocator;
90  UtlChain mPool;
91  UtlChain mBlocks;
95 };
96 
97 
98 #endif // UtlChainPool_h__
void release(UtlChain *freeChain)
Return freeLink to the pool of available UtlLinks.
Definition: UtlChainPool.cpp:61
UtlChainPool(allocator *blockAllocator, size_t blockSize)
Create a UtlChainPool that uses blockAllocator to create UtlChain derived objects.
Definition: UtlChainPool.cpp:29
void allocator(size_t blocksize, UtlChain *blockList, UtlChain *pool)
Allocate blocksize instances of the subclass and chain them into the pool.
Definition: UtlChainPool.h:49
Pool of available objects derived from UtlChain.
Definition: UtlChainPool.h:37
Definition: UtlLink.h:49
Utl initializer class. Solves the problem with ordering of constructors & destructors.
Definition: UtlInit.h:40
Associate a key object (the parent UtlLink data) with its value object.
Definition: UtlLink.h:457
size_t totalAllocated()
Returns the total number of subclasses instances allocated by this pool.
Definition: UtlChainPool.h:75