1 #ifndef UTIL___RESOURCEPOOL__HPP
2 #define UTIL___RESOURCEPOOL__HPP
257 template<
class Value,
274 :
TBase(capacity_upper_limit, cf)
302 typename Pool::TValue* ret =
m_Value;
332 template<
class Value,
354 size_t resource_pool_capacity_limit = 0)
381 for (
size_t i = 0;
i < bsize; ++
i) {
405 while (
m_Bucket.size() < backet+1) {
Bucket of resourse pools.
CNoLock is a simple no-op lock which does no real locking.
General purpose resource pool (base class, sans default constructor arguments for maximum versatility...
General purpose resource pool (standard version, requiring CF to have a default constructor).
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Lock::TWriteLockGuard TWriteLockGuard
void ForgetAll()
Makes pool to forget all objects.
void Return()
Return the protected object back to the pool.
Value * Get()
Get object from the pool.
CBucketPool & operator=(const CBucketPool &)
TBase::TClassFactory TClassFactory
void SetCapacityLimit(size_t capacity_upper_limit)
Set upper limit for pool capacity (everything above this is deleted)
CResourcePool_Base< Value, Lock, CF > TBase
Lock::TReadLockGuard TReadLockGuard
deque< Value * > TPoolList
Value * Forget(Value *v)
Makes the pool to forget the object.
const TPoolList & GetFreeList() const
Get internal list of free objects.
CResourcePool(size_t capacity_upper_limit=0, const TClassFactory &cf=TClassFactory())
void FreeAll()
Free all pool objects.
CResourcePoolGuard & operator=(const CResourcePoolGuard &)
void Put(Value *v)
Put object into the pool.
CBucketPool(const CBucketPool &)
CResourcePool_Base & operator=(const CResourcePool_Base &)
TBase::TPoolList TPoolList
Pool::TValue * Get()
Get the protected pointer.
static void Delete(Value *v)
TBase::TValuePtr TValuePtr
CResourcePool_Base(const CResourcePool_Base &)
CResourcePoolGuard(const CResourcePoolGuard &)
Lock::TWriteLockGuard TWriteLockGuard
CResourcePoolGuard(Pool &pool, typename Pool::TValue *v)
const TBucketVector & GetBucketVector() const
size_t m_ResourcePoolUpperLimit
size_t m_UpperLimit
Upper limit how much to pool.
vector< TResourcePool * > TBucketVector
CBucketPool(size_t bucket_ini=0, size_t resource_pool_capacity_limit=0)
Construction.
TPoolList & GetFreeList()
Get internal list of free objects.
TResourcePool * GetResourcePool(size_t backet)
Get resource pool for the specified backet.
CResourcePool & operator=(const CResourcePool &)
CResourcePool_Base(size_t capacity_upper_limit, const TClassFactory &cf)
Construction.
TBase::TWriteLockGuard TWriteLockGuard
void FreeAllPools()
Free all objects in all pools.
CResourcePool(const CResourcePool &)
Value * GetIfAvailable()
Get object from the pool if there is a vacancy, otherwise returns NULL.
TBase::TReadLockGuard TReadLockGuard
Pool::TValue * Release()
Return the pointer to the caller, not to the pool.
size_t GetCapacityLimit() const
Return max pool size.
size_t GetSize() const
Get current pool size (number of objects in the pool)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
CGuard< CRWLock, SSimpleReadLock< CRWLock > > TReadLockGuard
CGuard< CRWLock, SSimpleWriteLock< CRWLock > > TWriteLockGuard
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Multi-threading – mutexes; rw-locks; semaphore.
Default class factory for resource pool (C++ new/delete)