/usr/include/sipxtapi/utl/UtlChainPool.h is in libsipxtapi-dev 3.3.0~test17-2.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | //
// Copyright (C) 2004-2007 SIPfoundry Inc.
// Licensed by SIPfoundry under the LGPL license.
//
// Copyright (C) 2004-2007 Pingtel Corp. All rights reserved.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// $$
///////////////////////////////////////////////////////////////////////////////
#ifndef UtlChainPool_h__
#define UtlChainPool_h__
// SYSTEM INCLUDES
// APPLICATION INCLUDES
#include "utl/UtlLink.h"
// DEFINES
// MACROS
// EXTERNAL FUNCTIONS
// EXTERNAL VARIABLES
// CONSTANTS
// FORWARD DECLARATIONS
// STRUCTS
// TYPEDEFS
/// Pool of available objects derived from UtlChain.
/**
* This avoids excessive heap operations; rather than delete unused UtlChains, they are
* stored on the mPool here. To limit the heap overhead associated with allocating
* UtlChain, they are allocated in mBlockSize blocks, which are chained on
* mBlocks.
*
* The actual allocation of the blocks and initial chaining is done by the allocator
* function supplied by the UtlChain subclass.
*/
class UtlChainPool
{
/* //////////////////////////// PUBLIC //////////////////////////////////// */
public:
/* //////////////////////////// PROTECTED ///////////////////////////////// */
protected:
friend class UtlLink;
friend class UtlPair;
friend class UtlInit;
/// Allocate blocksize instances of the subclass and chain them into the pool.
typedef void allocator(size_t blocksize, ///< number of instances to allocate
UtlChain* blockList, ///< list header for first instance
UtlChain* pool ///< list header for others
);
/**<
* This function is supplied by the subclass to the UtlChainPool constructor.
* It is responsible for allocating a block of blocksize instances of its subclass.
* The first instance in each block is added to the blockList, so that the UtlChainPool
* destructor can delete the block. The remaining (blocksize-1) instances are
* chained onto the pool list header.
*/
/// Create a UtlChainPool that uses blockAllocator to create UtlChain derived objects.
UtlChainPool(allocator* blockAllocator, size_t blockSize);
/// Get a UtlLink with chain pointers NULL
UtlChain* get();
/// Return freeLink to the pool of available UtlLinks.
void release(UtlChain* freeChain);
/// Returns the total number of subclasses instances allocated by this pool.
/**
* The returned count does not include the 1 instance in each allocation that is
* consumed to manage the pool.
*/
size_t totalAllocated()
{
return mAllocations * (mBlockSize-1); // one per block is overhead
}
/* //////////////////////////// PRIVATE /////////////////////////////////// */
private:
/// Release all dynamic memory used by the UtlLinkPool.
~UtlChainPool();
OsBSem mLock; ///< lock for all the other member variables
size_t mBlockSize;
size_t mAllocations;
allocator* mAllocator;
UtlChain mPool; ///< list of available UtlLinks.
UtlChain mBlocks; /**< list of memory blocks allocated by the mAllocator.
* Each block is an mBlockSize array of objects derived from
* UtlChain. The 0th element is used to form the linked list
* of blocks. The rest are made a part of the mPool.*/
};
#endif // UtlChainPool_h__
|