NCBI C++ ToolKit
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions | Friends | List of all members
CPoolOfThreads< TRequest > Class Template Referenceabstract

Search Toolkit Book for CPoolOfThreads

CThreadInPool<> – abstract request-handling thread. More...

#include <util/thread_pool_old.hpp>

+ Inheritance diagram for CPoolOfThreads< TRequest >:
+ Collaboration diagram for CPoolOfThreads< TRequest >:

Public Types

typedef CThreadInPool< TRequest > TThread
typedef TThread::ERunMode ERunMode
typedef CBlockingQueue< TRequest > TQueue
typedef TQueue::TUserPriority TUserPriority
typedef TQueue::TItemHandle TItemHandle

Public Member Functions

 CPoolOfThreads (unsigned int max_threads, unsigned int queue_size, unsigned int spawn_threshold=1, unsigned int max_urgent_threads=kMax_UInt, const string &thread_name=kEmptyStr)
 Constructor. More...
virtual ~CPoolOfThreads (void)
 Destructor. More...
void Spawn (unsigned int num_threads)
 Start processing threads. More...
TItemHandle AcceptRequest (const TRequest &request, TUserPriority priority=0, unsigned int timeout_sec=0, unsigned int timeout_nsec=0)
 Put a request in the queue with a given priority. More...
TItemHandle AcceptUrgentRequest (const TRequest &request, unsigned int timeout_sec=0, unsigned int timeout_nsec=0)
 Puts a request in the queue with the highest priority It will run a new thread even if the maximum of allowed threads has been already reached. More...
void WaitForRoom (unsigned int timeout_sec=kMax_UInt, unsigned int timeout_nsec=0)
 Wait for the room in the queue up to timeout_sec + timeout_nsec/1E9 seconds. More...
bool IsFull (void) const
 Check if the queue is full. More...
bool IsEmpty (void) const
 Check if the queue is empty. More...
bool HasImmediateRoom (bool urgent=false) const
 Check whether a new request could be immediately processed. More...
void SetUserPriority (TItemHandle handle, TUserPriority priority)
 Adjust a pending request's priority. More...
void Withdraw (TItemHandle handle)
 Withdraw a pending request from consideration. More...
size_t GetQueueSize (void) const
 Get the number of requests in the queue. More...

Protected Types

typedef CAtomicCounter::TValue TACValue

Protected Member Functions

virtual TThreadNewThread (ERunMode mode)=0
 Create a new thread. More...
virtual void Register (TThread &thread)
 Register a thread. More...
virtual void UnRegister (TThread &)
 Unregister a thread. More...

Protected Attributes

CAtomicCounter_WithAutoInit m_MaxThreads
 The maximum number of threads the pool can hold. More...
CAtomicCounter_WithAutoInit m_MaxUrgentThreads
 The maximum number of urgent threads running simultaneously. More...
int m_Threshold
 for delta More...
CAtomicCounter_WithAutoInit m_ThreadCount
 The current number of threads in the pool. More...
CAtomicCounter_WithAutoInit m_UrgentThreadCount
 The current number of urgent threads running now. More...
atomic< intm_Delta
 The difference between the number of unfinished requests and the total number of threads in the pool. More...
CMutex m_Mutex
 The guard for m_MaxThreads, m_MaxUrgentThreads, and m_Delta. More...
TQueue m_Queue
 The request queue. More...
bool m_QueuingForbidden
const string m_ThreadName

Private Member Functions

TItemHandle x_AcceptRequest (const TRequest &req, TUserPriority priority, bool urgent, unsigned int timeout_sec=0, unsigned int timeout_nsec=0)
void x_RunNewThread (ERunMode mode, CAtomicCounter *counter)


class CThreadInPool< TRequest >

Detailed Description

template<typename TRequest>
class CPoolOfThreads< TRequest >

CThreadInPool<> – abstract request-handling thread.

CPoolOfThreads<> – abstract pool of threads sharing a request queue.

Definition at line 386 of file thread_pool_old.hpp.

The documentation for this class was generated from the following file:
Modified on Tue Apr 23 07:38:26 2024 by rev. 669887