NCBI C++ ToolKit
Classes | Typedefs | Enumerations | Enumerator | Functions | Variables | Friends
Threaded Pools for Request Handling
+ Collaboration diagram for Threaded Pools for Request Handling:

Classes

class  CQueueItemBase_ForServer
 
class  CBlockingQueue_ForServer
 
class  CBlockingQueue_ForServer::CCompletingHandle
 It may be desirable to store handles obtained from GetHandle() in instances of CCompletingHandle to ensure that they are marked as complete when all is said and done, even in the face of exceptions. More...
 
class  CBlockingQueue_ForServer::CQueueItem
 
class  CThreadInPool_ForServer
 
class  CThreadInPool_ForServer::CAutoUnregGuard
 
class  CPoolOfThreads_ForServer
 
class  CThreadPool_Task
 Abstract class for representing single task executing in pool of threads To use this class in application you should inherit your own class from it and define method Execute() - the main method where all task logic executes. More...
 
class  CThreadPool
 Main class implementing functionality of pool of threads. More...
 
class  CThreadPool_Thread
 Base class for a thread running inside CThreadPool and executing tasks. More...
 
class  CThreadPool_Controller
 Abstract class for controlling the number of threads in pool. More...
 
class  CThreadPoolException
 Exception class for all ThreadPool-related classes. More...
 
struct  SThreadPool_PID_ErrInfo
 Entry in "error" changing history Information about "error" in some point of time in the past kept in CThreadPool_Control_PID. More...
 
class  CThreadPool_Controller_PID
 Default ThreadPool controller based on Proportional-Integral-Derivative algorithm. More...
 
class  CQueueItemBase
 CQueueItemBase – skeleton blocking-queue item, sans actual request. More...
 
class  CBlockingQueue< TRequest >
 CBlockingQueue<> – queue of requests, with efficiently blocking Get() More...
 
class  CBlockingQueue< TRequest >::CCompletingHandle
 It may be desirable to store handles obtained from GetHandle() in instances of CCompletingHandle to ensure that they are marked as complete when all is said and done, even in the face of exceptions. More...
 
class  CBlockingQueue< TRequest >::CQueueItem
 
struct  CBlockingQueue< TRequest >::SItemHandleGreater
 
class  CPoolOfThreads< TRequest >
 CThreadInPool<> – abstract request-handling thread. More...
 
class  CThreadInPool< TRequest >
 
class  CThreadInPool< TRequest >::CAutoUnregGuard
 
class  CStdRequest
 
class  CStdThreadInPool
 
class  CStdPoolOfThreads
 

Typedefs

typedef CQueueItemBase::EStatus CQueueItemBase_ForServer::EStatus
 
typedef CRef< CQueueItemCBlockingQueue_ForServer::TItemHandle
 
typedef CRef< CStdRequestCBlockingQueue_ForServer::TRequest
 
typedef deque< TItemHandleCBlockingQueue_ForServer::TRealQueue
 The type of the queue. More...
 
typedef CPoolOfThreads_ForServer CThreadInPool_ForServer::TPool
 
typedef CBlockingQueue_ForServer::TItemHandle CThreadInPool_ForServer::TItemHandle
 
typedef CBlockingQueue_ForServer::CCompletingHandle CThreadInPool_ForServer::TCompletingHandle
 
typedef CBlockingQueue_ForServer::TRequest CThreadInPool_ForServer::TRequest
 
typedef CThreadInPool_ForServer CThreadInPool_ForServer::CAutoUnregGuard::TThread
 
typedef CThreadInPool_ForServer CPoolOfThreads_ForServer::TThread
 
typedef CBlockingQueue_ForServer CPoolOfThreads_ForServer::TQueue
 
typedef TQueue::TItemHandle CPoolOfThreads_ForServer::TItemHandle
 
typedef TQueue::TRequest CPoolOfThreads_ForServer::TRequest
 
typedef CAtomicCounter::TValue CPoolOfThreads_ForServer::TACValue
 
typedef list< CRef< TThread > > CPoolOfThreads_ForServer::TThreads
 
typedef unsigned int CThreadPool::TExclusiveFlags
 Type of bit-masked combination of several values from EExclusiveFlags. More...
 
typedef Uint4 CQueueItemBase::TPriority
 Every request has an associated 32-bit priority field, but only the top eight bits are under direct user control. More...
 
typedef Uint1 CQueueItemBase::TUserPriority
 
typedef CQueueItemBase::TPriority CBlockingQueue< TRequest >::TPriority
 
typedef CQueueItemBase::TUserPriority CBlockingQueue< TRequest >::TUserPriority
 
typedef CRef< CQueueItemCBlockingQueue< TRequest >::TItemHandle
 
typedef set< TItemHandle, SItemHandleGreaterCBlockingQueue< TRequest >::TRealQueue
 The type of the queue. More...
 
typedef bool(CBlockingQueue::* CBlockingQueue< TRequest >::TQueuePredicate) (const TRealQueue &q) const
 
typedef CPoolOfThreads< TRequest > CThreadInPool< TRequest >::TPool
 
typedef CBlockingQueue< TRequest >::TItemHandle CThreadInPool< TRequest >::TItemHandle
 
typedef CBlockingQueue< TRequest >::CCompletingHandle CThreadInPool< TRequest >::TCompletingHandle
 
typedef CThreadInPool< TRequest > CThreadInPool< TRequest >::CAutoUnregGuard::TThread
 
typedef CThreadInPool< TRequest > CPoolOfThreads< TRequest >::TThread
 
typedef TThread::ERunMode CPoolOfThreads< TRequest >::ERunMode
 
typedef CBlockingQueue< TRequest > CPoolOfThreads< TRequest >::TQueue
 
typedef TQueue::TUserPriority CPoolOfThreads< TRequest >::TUserPriority
 
typedef TQueue::TItemHandle CPoolOfThreads< TRequest >::TItemHandle
 
typedef CAtomicCounter::TValue CPoolOfThreads< TRequest >::TACValue
 
typedef CQueueItemBase::EStatus CStdRequest::EStatus
 
typedef CThreadInPool< CRef< CStdRequest > > CStdThreadInPool::TParent
 
typedef CPoolOfThreads< CRef< CStdRequest > > CStdPoolOfThreads::TParent
 
typedef int CStdPoolOfThreads::TKillFlags
 binary OR of EKillFlags More...
 
typedef list< CRef< TThread > > CStdPoolOfThreads::TThreads
 

Enumerations

enum  CThreadPool_Task::EStatus {
  CThreadPool_Task::eIdle , CThreadPool_Task::eQueued , CThreadPool_Task::eExecuting , CThreadPool_Task::eCompleted ,
  CThreadPool_Task::eFailed , CThreadPool_Task::eCanceled
}
 Status of the task. More...
 
enum  CThreadPool::EExclusiveFlags {
  CThreadPool::fDoNotAllowNewTasks = (1 << 0) , CThreadPool::fFlushThreads = (1 << 1) , CThreadPool::fCancelExecutingTasks = (1 << 2) , CThreadPool::fCancelQueuedTasks = (1 << 3) ,
  CThreadPool::fExecuteQueuedTasks = (1 << 4)
}
 Binary flags indicating different possible options in what environment the pool will execute exclusive task. More...
 
enum  CThreadPool::EFlushType { CThreadPool::eStartImmediately , CThreadPool::eWaitToFinish }
 When to start new threads after flushing old ones. More...
 
enum  CThreadPool_Controller::EEvent { CThreadPool_Controller::eSuspend , CThreadPool_Controller::eResume , CThreadPool_Controller::eOther }
 Events that can happen with ThreadPool. More...
 
enum  CThreadPoolException::EErrCode {
  CThreadPoolException::eControllerBusy , CThreadPoolException::eTaskBusy , CThreadPoolException::eProhibited , CThreadPoolException::eInactive ,
  CThreadPoolException::eInvalid
}
 
enum  CQueueItemBase::EStatus {
  CQueueItemBase::ePending , CQueueItemBase::eActive , CQueueItemBase::eComplete , CQueueItemBase::eWithdrawn ,
  CQueueItemBase::eForciblyCaught
}
 
enum  CThreadInPool< TRequest >::ERunMode { CThreadInPool< TRequest >::eNormal , CThreadInPool< TRequest >::eRunOnce }
 Thread run mode. More...
 
enum  CStdPoolOfThreads::EKillFlags { CStdPoolOfThreads::fKill_Wait = 0x1 , CStdPoolOfThreads::fKill_Reopen = 0x2 }
 

Functions

 CQueueItemBase_ForServer::CQueueItemBase_ForServer (void)
 
const EStatusCQueueItemBase_ForServer::GetStatus (void) const
 
void CQueueItemBase_ForServer::MarkAsComplete (void)
 
void CQueueItemBase_ForServer::MarkAsForciblyCaught (void)
 
virtual void CQueueItemBase_ForServer::x_SetStatus (EStatus new_status)
 
 CBlockingQueue_ForServer::CCompletingHandle::CCompletingHandle (const TItemHandle &h)
 
 CBlockingQueue_ForServer::CCompletingHandle::~CCompletingHandle ()
 
 CBlockingQueue_ForServer::CBlockingQueue_ForServer (void)
 Constructor. More...
 
TItemHandle CBlockingQueue_ForServer::Put (const TRequest &request)
 Put a request into the queue. More...
 
TItemHandle CBlockingQueue_ForServer::GetHandle (void)
 Get the first available request from the queue, and return a handle to it. More...
 
 CBlockingQueue_ForServer::CQueueItem::CQueueItem (TRequest request)
 
const TRequestCBlockingQueue_ForServer::CQueueItem::GetRequest (void) const
 
void CBlockingQueue_ForServer::CQueueItem::x_SetStatus (EStatus new_status)
 
 CBlockingQueue_ForServer::CBlockingQueue_ForServer (const CBlockingQueue_ForServer &)
 forbidden More...
 
CBlockingQueue_ForServerCBlockingQueue_ForServer::operator= (const CBlockingQueue_ForServer &)
 
 CThreadInPool_ForServer::CThreadInPool_ForServer (TPool *pool)
 Constructor. More...
 
void CThreadInPool_ForServer::CountSelf (void)
 
virtual CThreadInPool_ForServer::~CThreadInPool_ForServer (void)
 Destructor. More...
 
void CThreadInPool_ForServer::ProcessRequest (TItemHandle handle)
 Process a request. More...
 
void CThreadInPool_ForServer::ProcessRequest (const TRequest &req)
 Older interface (still delegated to by default) More...
 
virtual void * CThreadInPool_ForServer::Main (void)
 Derived (user-created) class must provide a real thread function. More...
 
void CThreadInPool_ForServer::x_HandleOneRequest (bool catch_all)
 
void CThreadInPool_ForServer::x_UnregisterThread (void)
 
 CThreadInPool_ForServer::CAutoUnregGuard::CAutoUnregGuard (TThread *thr)
 
 CThreadInPool_ForServer::CAutoUnregGuard::~CAutoUnregGuard (void)
 
 CPoolOfThreads_ForServer::CPoolOfThreads_ForServer (unsigned int max_threads, const string &thr_suffix)
 Constructor. More...
 
virtual CPoolOfThreads_ForServer::~CPoolOfThreads_ForServer (void)
 Destructor. More...
 
void CPoolOfThreads_ForServer::Spawn (unsigned int num_threads)
 Start processing threads. More...
 
void CPoolOfThreads_ForServer::AcceptRequest (const TRequest &request)
 Put a request in the queue with a given priority. More...
 
TItemHandle CPoolOfThreads_ForServer::GetHandle (void)
 
void CPoolOfThreads_ForServer::KillAllThreads (bool wait)
 Causes all threads in the pool to exit cleanly after finishing all pending requests, optionally waiting for them to die. More...
 
TThreadCPoolOfThreads_ForServer::NewThread (void)
 Create a new thread. More...
 
bool CPoolOfThreads_ForServer::Register (TThread &thread)
 Register a thread. More...
 
void CPoolOfThreads_ForServer::UnRegister (TThread &)
 Unregister a thread. More...
 
 CThreadPool_Task::CThreadPool_Task (unsigned int priority=0)
 Constructor. More...
 
virtual EStatus CThreadPool_Task::Execute (void)=0
 Do the actual job. More...
 
void CThreadPool_Task::RequestToCancel (void)
 Cancel the task. More...
 
bool CThreadPool_Task::IsCancelRequested (void) const
 Check if cancellation of the task was requested. More...
 
EStatus CThreadPool_Task::GetStatus (void) const
 Get status of the task. More...
 
bool CThreadPool_Task::IsFinished (void) const
 Check if task execution has been already finished (successfully or not) More...
 
unsigned int CThreadPool_Task::GetPriority (void) const
 Get priority of the task. More...
 
virtual void CThreadPool_Task::OnStatusChange (EStatus old)
 Callback to notify on changes in the task status. More...
 
virtual void CThreadPool_Task::OnCancelRequested (void)
 Callback to notify when cancellation of the task is requested. More...
 
 CThreadPool_Task::CThreadPool_Task (const CThreadPool_Task &other)
 Copy ctor. More...
 
CThreadPool_TaskCThreadPool_Task::operator= (const CThreadPool_Task &other)
 Assignment. More...
 
CThreadPoolCThreadPool_Task::GetPool (void) const
 The thread pool which accepted this task for execution. More...
 
virtual CThreadPool_Task::~CThreadPool_Task (void)
 Destructor. Will be called from CRef. More...
 
void CThreadPool_Task::x_Init (unsigned int priority)
 Init all members in constructor. More...
 
void CThreadPool_Task::x_SetOwner (CThreadPool_Impl *pool)
 Set pool as owner of this task. More...
 
void CThreadPool_Task::x_ResetOwner (void)
 Detach task from the pool (if insertion into the pool has failed). More...
 
void CThreadPool_Task::x_SetStatus (EStatus new_status)
 Set task status. More...
 
void CThreadPool_Task::x_RequestToCancel (void)
 Internal canceling of the task. More...
 
 CThreadPool::CThreadPool (unsigned int queue_size, unsigned int max_threads, unsigned int min_threads=2, CThread::TRunMode threads_mode=CThread::fRunDefault)
 Constructor. More...
 
void CThreadPool::AddTask (CThreadPool_Task *task, const CTimeSpan *timeout=NULL)
 Add task to the pool for execution. More...
 
void CThreadPool::CancelTask (CThreadPool_Task *task)
 Request to cancel the task and remove it from queue if it is there. More...
 
virtual CThreadPool::~CThreadPool (void)
 Destructor – will wait for all its threads to finish with the timeout set by CThreadPool::SetDestroyTimeout(); current default is 10 seconds. More...
 
void CThreadPool::Abort (const CTimeSpan *timeout=NULL)
 Abort all functions of the pool – cancel all queued tasks, send cancellation notifications to all currently executing tasks. More...
 
 CThreadPool::CThreadPool (unsigned int queue_size, CThreadPool_Controller *controller, CThread::TRunMode threads_mode=CThread::fRunDefault)
 Constructor with custom controller. More...
 
void CThreadPool::SetDestroyTimeout (const CTimeSpan &timeout)
 Set timeout to wait for all threads to finish before the pool should be able to destroy. More...
 
const CTimeSpanCThreadPool::GetDestroyTimeout (void) const
 Get timeout to wait for all threads to finish before the pool will be able to destroy. More...
 
void CThreadPool::RequestExclusiveExecution (CThreadPool_Task *task, TExclusiveFlags flags=0)
 Add the task for exclusive execution in the pool By default the pool suspends all new and queued tasks processing, finishes execution of all currently executing tasks and then executes exclusive task in special thread devoted to this work. More...
 
void CThreadPool::CancelTasks (TExclusiveFlags tasks_group)
 Cancel the selected groups of tasks in the pool. More...
 
void CThreadPool::FlushThreads (EFlushType flush_type)
 Finish all current threads and replace them with new ones. More...
 
unsigned int CThreadPool::GetThreadsCount (void) const
 Get total number of threads currently running in pool. More...
 
unsigned int CThreadPool::GetQueuedTasksCount (void) const
 Get the number of tasks currently waiting in queue. More...
 
unsigned int CThreadPool::GetExecutingTasksCount (void) const
 Get the number of currently executing tasks. More...
 
bool CThreadPool::IsAborted (void) const
 Does method Abort() was already called for this ThreadPool. More...
 
virtual CThreadPool_ThreadCThreadPool::CreateThread (void)
 Create new thread for the pool. More...
 
CMutexCThreadPool::GetMainPoolMutex (void)
 Get the mutex that protects all changes in the pool. More...
 
 CThreadPool::CThreadPool (const CThreadPool &)
 Prohibit copying and assigning. More...
 
CThreadPoolCThreadPool::operator= (const CThreadPool &)
 
CRef< CThreadPool_TaskCThreadPool_Thread::GetCurrentTask (void) const
 Get the task currently executing in the thread. More...
 
 CThreadPool_Thread::CThreadPool_Thread (CThreadPool *pool)
 Construct and attach to the pool. More...
 
virtual CThreadPool_Thread::~CThreadPool_Thread (void)
 Destructor. More...
 
virtual void CThreadPool_Thread::Initialize (void)
 Init this thread. It is called at beginning of Main() More...
 
virtual void CThreadPool_Thread::Finalize (void)
 Clean up. It is called by OnExit() More...
 
CThreadPoolCThreadPool_Thread::GetPool (void) const
 Get the thread pool in which this thread is running. More...
 
 CThreadPool_Thread::CThreadPool_Thread (const CThreadPool_Thread &)
 Prohibit copying and assigning. More...
 
CThreadPool_ThreadCThreadPool_Thread::operator= (const CThreadPool_Thread &)
 
virtual void * CThreadPool_Thread::Main (void)
 To prevent overriding - main thread function. More...
 
virtual void CThreadPool_Thread::OnExit (void)
 To prevent overriding - do cleanup after exiting from thread. More...
 
 CThreadPool_Controller::CThreadPool_Controller (unsigned int max_threads, unsigned int min_threads)
 Constructor. More...
 
void CThreadPool_Controller::SetMinThreads (unsigned int min_threads)
 Set the minimum number of threads in pool. More...
 
unsigned int CThreadPool_Controller::GetMinThreads (void) const
 Get the minimum number of threads in pool. More...
 
void CThreadPool_Controller::SetMaxThreads (unsigned int max_threads)
 Set the maximum number of threads in pool. More...
 
unsigned int CThreadPool_Controller::GetMaxThreads (void) const
 Get the maximum number of threads in pool. More...
 
void CThreadPool_Controller::HandleEvent (EEvent event)
 This method is called every time something happens in a pool, such as: new task added, task is started or finished execution, new threads started or some threads finished. More...
 
virtual CTimeSpan CThreadPool_Controller::GetSafeSleepTime (void) const
 Get maximum timeout for which calls to method HandleEvent() can be missing. More...
 
virtual CThreadPool_Controller::~CThreadPool_Controller (void)
 Destructor. Have to be called only from CRef. More...
 
virtual void CThreadPool_Controller::OnEvent (EEvent event)=0
 Main method for the implementation of controlling algorithm. More...
 
CThreadPoolCThreadPool_Controller::GetPool (void) const
 Get pool to which this class is attached. More...
 
CMutexCThreadPool_Controller::GetMainPoolMutex (CThreadPool *pool) const
 Get mutex which guards access to pool All work in controller should be based on the same mutex as in pool. More...
 
void CThreadPool_Controller::EnsureLimits (void)
 Ensure that constraints of minimum and maximum count of threads in pool are met. More...
 
void CThreadPool_Controller::SetThreadsCount (unsigned int count)
 Set number of threads in pool Adjust given number to conform to minimum and maximum threads count constraints if needed. More...
 
 CThreadPool_Controller::CThreadPool_Controller (const CThreadPool_Controller &)
 Prohibit copying and assigning. More...
 
CThreadPool_ControllerCThreadPool_Controller::operator= (const CThreadPool_Controller &)
 
void CThreadPool_Controller::x_AttachToPool (CThreadPool_Impl *pool)
 Attach the controller to ThreadPool. More...
 
void CThreadPool_Controller::x_DetachFromPool (void)
 Detach the controller from pool when pool is aborted. More...
 
virtual const char * CThreadPoolException::GetErrCodeString (void) const override
 Get error code interpreted as text. More...
 
 CThreadPoolException::NCBI_EXCEPTION_DEFAULT (CThreadPoolException, CException)
 
 SThreadPool_PID_ErrInfo::SThreadPool_PID_ErrInfo (double time_, double err_)
 
 CThreadPool_Controller_PID::CThreadPool_Controller_PID (unsigned int max_threads, unsigned int min_threads)
 Constructor. More...
 
void CThreadPool_Controller_PID::SetQueuedTasksThreshold (double threshold)
 Set maximum number of tasks in queue per each thread The meaning of parameter is only approximate. More...
 
double CThreadPool_Controller_PID::GetQueuedTasksThreshold (void)
 Get maximum number of tasks in queue per each thread. More...
 
void CThreadPool_Controller_PID::SetTaskMaxQueuedTime (double queued_time)
 Set maximum time (in seconds) that task can wait in queue for processing until new thread will be launched. More...
 
double CThreadPool_Controller_PID::GetTaskMaxQueuedTime (void)
 Get maximum time that task can wait in queue for processing until new thread will be launched. More...
 
void CThreadPool_Controller_PID::SetChangeCalcTime (double calc_time)
 Set the time period (in seconds) for which average speed of changing of waiting tasks number is calculated. More...
 
double CThreadPool_Controller_PID::GetChangeCalcTime (void)
 Get the time period for which average speed of changing of waiting tasks number is calculated. More...
 
void CThreadPool_Controller_PID::SetChangePredictTime (double predict_time)
 Set period of prediction of number of tasks in queue The meaning of parameter is only approximate. More...
 
double CThreadPool_Controller_PID::GetChangePredictTime (void)
 Get period of prediction of number of tasks in queue. More...
 
virtual CTimeSpan CThreadPool_Controller_PID::GetSafeSleepTime (void) const
 Get maximum timeout for which calls to method HandleEvent() can be missing. More...
 
virtual void CThreadPool_Controller_PID::OnEvent (EEvent event)
 Main method for implementation of controlling algorithm. More...
 
 CQueueItemBase::CQueueItemBase (TPriority priority)
 
bool CQueueItemBase::operator> (const CQueueItemBase &item) const
 
const TPriorityCQueueItemBase::GetPriority (void) const
 
const EStatusCQueueItemBase::GetStatus (void) const
 
TUserPriority CQueueItemBase::GetUserPriority (void) const
 
void CQueueItemBase::MarkAsComplete (void)
 
void CQueueItemBase::MarkAsForciblyCaught (void)
 
virtual void CQueueItemBase::x_SetStatus (EStatus new_status)
 
 CBlockingQueue< TRequest >::CCompletingHandle::CCompletingHandle (const TItemHandle &h)
 
 CBlockingQueue< TRequest >::CCompletingHandle::~CCompletingHandle ()
 
 CBlockingQueue< TRequest >::CBlockingQueue (size_t max_size=kMax_UInt)
 Constructor. More...
 
TItemHandle CBlockingQueue< TRequest >::Put (const TRequest &request, TUserPriority priority=0, unsigned int timeout_sec=0, unsigned int timeout_nsec=0)
 Put a request into the queue. More...
 
void CBlockingQueue< TRequest >::WaitForRoom (unsigned int timeout_sec=kMax_UInt, unsigned int timeout_nsec=0) const
 Wait for room in the queue for up to timeout_sec + timeout_nsec/1E9 seconds. More...
 
void CBlockingQueue< TRequest >::WaitForHunger (unsigned int timeout_sec=kMax_UInt, unsigned int timeout_nsec=0) const
 Wait for the queue to have waiting readers, for up to timeout_sec + timeout_nsec/1E9 seconds. More...
 
TItemHandle CBlockingQueue< TRequest >::GetHandle (unsigned int timeout_sec=kMax_UInt, unsigned int timeout_nsec=0)
 Get the first available request from the queue, and return a handle to it. More...
 
TRequest CBlockingQueue< TRequest >::Get (unsigned int timeout_sec=kMax_UInt, unsigned int timeout_nsec=0)
 Get the first available request from the queue, and return just the request. More...
 
size_t CBlockingQueue< TRequest >::GetSize (void) const
 Get the number of requests in the queue. More...
 
size_t CBlockingQueue< TRequest >::GetMaxSize (void) const
 Get the maximun number of requests that can be put into the queue. More...
 
bool CBlockingQueue< TRequest >::IsEmpty (void) const
 Check if the queue is empty. More...
 
bool CBlockingQueue< TRequest >::IsFull (void) const
 Check if the queue is full. More...
 
void CBlockingQueue< TRequest >::SetUserPriority (TItemHandle handle, TUserPriority priority)
 Adjust a pending request's priority. More...
 
void CBlockingQueue< TRequest >::Withdraw (TItemHandle handle)
 Withdraw a pending request from consideration. More...
 
size_t CBlockingQueue< TRequest >::GetHunger (void) const
 Get the number of threads waiting for requests, for debugging purposes only. More...
 
 CBlockingQueue< TRequest >::CQueueItem::CQueueItem (Uint4 priority, TRequest request)
 
const TRequest & CBlockingQueue< TRequest >::CQueueItem::GetRequest (void) const
 
TRequest & CBlockingQueue< TRequest >::CQueueItem::SetRequest (void)
 
void CBlockingQueue< TRequest >::CQueueItem::x_SetStatus (EStatus new_status)
 
bool CBlockingQueue< TRequest >::SItemHandleGreater::operator() (const TItemHandle &i1, const TItemHandle &i2) const
 
bool CBlockingQueue< TRequest >::x_GetSemPred (const TRealQueue &q) const
 
bool CBlockingQueue< TRequest >::x_PutSemPred (const TRealQueue &q) const
 
bool CBlockingQueue< TRequest >::x_HungerSemPred (const TRealQueue &q) const
 
bool CBlockingQueue< TRequest >::x_WaitForPredicate (TQueuePredicate pred, CSemaphore &sem, CMutexGuard &guard, unsigned int timeout_sec, unsigned int timeout_nsec) const
 
 CBlockingQueue< TRequest >::CBlockingQueue (const CBlockingQueue &)
 forbidden More...
 
CBlockingQueueCBlockingQueue< TRequest >::operator= (const CBlockingQueue &)
 
 CThreadInPool< TRequest >::CThreadInPool (TPool *pool, ERunMode mode=eNormal)
 Constructor. More...
 
void CThreadInPool< TRequest >::CountSelf (CAtomicCounter *counter)
 
virtual CThreadInPool< TRequest >::~CThreadInPool (void)
 Destructor. More...
 
virtual void CThreadInPool< TRequest >::Init (void)
 Intit this thread. It is called at beginning of Main() More...
 
virtual void CThreadInPool< TRequest >::ProcessRequest (TItemHandle handle)
 Process a request. More...
 
virtual void CThreadInPool< TRequest >::ProcessRequest (const TRequest &req)=0
 Older interface (still delegated to by default) More...
 
virtual void CThreadInPool< TRequest >::x_OnExit (void)
 Clean up. It is called by OnExit() More...
 
ERunMode CThreadInPool< TRequest >::GetRunMode (void) const
 Get run mode. More...
 
virtual void * CThreadInPool< TRequest >::Main (void)
 Derived (user-created) class must provide a real thread function. More...
 
virtual void CThreadInPool< TRequest >::OnExit (void)
 Override this to execute finalization code. More...
 
void CThreadInPool< TRequest >::x_HandleOneRequest (bool catch_all)
 
void CThreadInPool< TRequest >::x_UnregisterThread (void)
 
 CThreadInPool< TRequest >::CAutoUnregGuard::CAutoUnregGuard (TThread *thr)
 
 CThreadInPool< TRequest >::CAutoUnregGuard::~CAutoUnregGuard (void)
 
 CPoolOfThreads< TRequest >::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< TRequest >::~CPoolOfThreads (void)
 Destructor. More...
 
void CPoolOfThreads< TRequest >::Spawn (unsigned int num_threads)
 Start processing threads. More...
 
TItemHandle CPoolOfThreads< TRequest >::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 CPoolOfThreads< TRequest >::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 CPoolOfThreads< TRequest >::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 CPoolOfThreads< TRequest >::IsFull (void) const
 Check if the queue is full. More...
 
bool CPoolOfThreads< TRequest >::IsEmpty (void) const
 Check if the queue is empty. More...
 
bool CPoolOfThreads< TRequest >::HasImmediateRoom (bool urgent=false) const
 Check whether a new request could be immediately processed. More...
 
void CPoolOfThreads< TRequest >::SetUserPriority (TItemHandle handle, TUserPriority priority)
 Adjust a pending request's priority. More...
 
void CPoolOfThreads< TRequest >::Withdraw (TItemHandle handle)
 Withdraw a pending request from consideration. More...
 
size_t CPoolOfThreads< TRequest >::GetQueueSize (void) const
 Get the number of requests in the queue. More...
 
virtual TThreadCPoolOfThreads< TRequest >::NewThread (ERunMode mode)=0
 Create a new thread. More...
 
virtual void CPoolOfThreads< TRequest >::Register (TThread &thread)
 Register a thread. More...
 
virtual void CPoolOfThreads< TRequest >::UnRegister (TThread &)
 Unregister a thread. More...
 
TItemHandle CPoolOfThreads< TRequest >::x_AcceptRequest (const TRequest &req, TUserPriority priority, bool urgent, unsigned int timeout_sec=0, unsigned int timeout_nsec=0)
 
void CPoolOfThreads< TRequest >::x_RunNewThread (ERunMode mode, CAtomicCounter *counter)
 
virtual CStdRequest::~CStdRequest (void)
 Destructor. More...
 
virtual void CStdRequest::Process (void)=0
 Do the actual job Called by whichever thread handles this request. More...
 
virtual void CStdRequest::OnStatusChange (EStatus, EStatus)
 Callback for status changes. More...
 
 CStdThreadInPool::CStdThreadInPool (TPool *pool, ERunMode mode=eNormal)
 Constructor. More...
 
virtual void CStdThreadInPool::ProcessRequest (const CRef< CStdRequest > &req)
 Process a request. More...
 
virtual void CStdThreadInPool::ProcessRequest (TItemHandle handle)
 
 CStdPoolOfThreads::CStdPoolOfThreads (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 CStdPoolOfThreads::~CStdPoolOfThreads ()
 
virtual void CStdPoolOfThreads::KillAllThreads (TKillFlags flags)
 Causes all threads in the pool to exit cleanly after finishing all pending requests, optionally waiting for them to die. More...
 
virtual void CStdPoolOfThreads::KillAllThreads (bool wait)
 Causes all threads in the pool to exit cleanly after finishing all pending requests, optionally waiting for them to die. More...
 
virtual void CStdPoolOfThreads::Register (TThread &thread)
 Register a thread. More...
 
virtual void CStdPoolOfThreads::UnRegister (TThread &thread)
 Unregister a thread. More...
 
virtual TThreadCStdPoolOfThreads::NewThread (TThread::ERunMode mode)
 Create a new thread. More...
 
 NCBI_PARAM_DECL (bool, ThreadPool, Catch_Unhandled_Exceptions)
 
typedef NCBI_PARAM_TYPE (ThreadPool, Catch_Unhandled_Exceptions) TParamThreadPoolCatchExceptions
 

Variables

EStatus CQueueItemBase_ForServer::m_Status
 
TRequest CBlockingQueue_ForServer::CQueueItem::m_Request
 
TRealQueue CBlockingQueue_ForServer::m_Queue
 The queue. More...
 
CConditionVariable CBlockingQueue_ForServer::m_GetCond
 
CMutex CBlockingQueue_ForServer::m_Mutex
 Guards access to queue. More...
 
TThreadCThreadInPool_ForServer::CAutoUnregGuard::m_Thread
 
TPoolCThreadInPool_ForServer::m_Pool
 The pool that holds this thread. More...
 
bool CThreadInPool_ForServer::m_Counted
 
volatile TACValue CPoolOfThreads_ForServer::m_MaxThreads
 The maximum number of threads the pool can hold. More...
 
CAtomicCounter CPoolOfThreads_ForServer::m_ThreadCount
 The current number of threads in the pool. More...
 
CMutex CPoolOfThreads_ForServer::m_Mutex
 The guard for m_MaxThreads and m_MaxUrgentThreads. More...
 
TQueue CPoolOfThreads_ForServer::m_Queue
 
string CPoolOfThreads_ForServer::m_ThrSuffix
 
TThreads CPoolOfThreads_ForServer::m_Threads
 
bool CPoolOfThreads_ForServer::m_KilledAll
 
CAtomicCounter_WithAutoInit CThreadPool_Task::m_IsBusy
 Flag indicating that the task is already added to some pool. More...
 
atomic< CThreadPool_Impl * > CThreadPool_Task::m_Pool
 Pool owning this task. More...
 
unsigned int CThreadPool_Task::m_Priority
 Priority of the task. More...
 
atomic< EStatusCThreadPool_Task::m_Status
 Status of the task. More...
 
atomic< boolCThreadPool_Task::m_CancelRequested
 Flag indicating if cancellation of the task was already requested. More...
 
CThreadPool_ImplCThreadPool::m_Impl
 Actual implementation of the pool. More...
 
CThreadPool_ThreadImplCThreadPool_Thread::m_Impl
 Actual implementation of the thread. More...
 
atomic< CThreadPool_Impl * > CThreadPool_Controller::m_Pool
 ThreadPool to which this controller is attached. More...
 
unsigned int CThreadPool_Controller::m_MinThreads
 Minimum number of threads in pool. More...
 
unsigned int CThreadPool_Controller::m_MaxThreads
 Maximum number of threads in pool. More...
 
bool CThreadPool_Controller::m_InHandleEvent
 If controller is already inside HandleEvent() processing. More...
 
double SThreadPool_PID_ErrInfo::call_time
 Time of history entry. More...
 
double SThreadPool_PID_ErrInfo::err
 Value of the error. More...
 
CStopWatch CThreadPool_Controller_PID::m_Timer
 Timer for measuring time periods. More...
 
deque< SThreadPool_PID_ErrInfoCThreadPool_Controller_PID::m_ErrHistory
 History of changing of "error" value "error" - number of tasks per thread waiting in queue. More...
 
double CThreadPool_Controller_PID::m_IntegrErr
 Value of "error" integrated over all working time. More...
 
double CThreadPool_Controller_PID::m_Threshold
 Threshold value. More...
 
double CThreadPool_Controller_PID::m_IntegrCoeff
 Integral coefficient. More...
 
double CThreadPool_Controller_PID::m_DerivCoeff
 Derivative coefficient. More...
 
double CThreadPool_Controller_PID::m_DerivTime
 Period of taking average "error" change speed. More...
 
TPriority CQueueItemBase::m_Priority
 
EStatus CQueueItemBase::m_Status
 
TRequest CBlockingQueue< TRequest >::CQueueItem::m_Request
 
volatile TRealQueue CBlockingQueue< TRequest >::m_Queue
 The queue. More...
 
CSemaphore CBlockingQueue< TRequest >::m_GetSem
 Raised if the queue contains data. More...
 
CSemaphore CBlockingQueue< TRequest >::m_PutSem
 Raised if the queue has room. More...
 
CSemaphore CBlockingQueue< TRequest >::m_HungerSem
 Raised if Get[Handle] has to wait. More...
 
CMutex CBlockingQueue< TRequest >::m_Mutex
 Guards access to queue. More...
 
size_t CBlockingQueue< TRequest >::m_HungerCnt
 Number of threads waiting for data. More...
 
size_t CBlockingQueue< TRequest >::m_MaxSize
 The maximum size of the queue. More...
 
Uint4 CBlockingQueue< TRequest >::m_RequestCounter
 
TThreadCThreadInPool< TRequest >::CAutoUnregGuard::m_Thread
 
TPoolCThreadInPool< TRequest >::m_Pool
 The pool that holds this thread. More...
 
ERunMode CThreadInPool< TRequest >::m_RunMode
 How long to keep running. More...
 
CAtomicCounterCThreadInPool< TRequest >::m_Counter
 
CAtomicCounter_WithAutoInit CPoolOfThreads< TRequest >::m_MaxThreads
 The maximum number of threads the pool can hold. More...
 
CAtomicCounter_WithAutoInit CPoolOfThreads< TRequest >::m_MaxUrgentThreads
 The maximum number of urgent threads running simultaneously. More...
 
int CPoolOfThreads< TRequest >::m_Threshold
 for delta More...
 
CAtomicCounter_WithAutoInit CPoolOfThreads< TRequest >::m_ThreadCount
 The current number of threads in the pool. More...
 
CAtomicCounter_WithAutoInit CPoolOfThreads< TRequest >::m_UrgentThreadCount
 The current number of urgent threads running now. More...
 
atomic< intCPoolOfThreads< TRequest >::m_Delta
 The difference between the number of unfinished requests and the total number of threads in the pool. More...
 
CMutex CPoolOfThreads< TRequest >::m_Mutex
 The guard for m_MaxThreads, m_MaxUrgentThreads, and m_Delta. More...
 
TQueue CPoolOfThreads< TRequest >::m_Queue
 The request queue. More...
 
bool CPoolOfThreads< TRequest >::m_QueuingForbidden
 
const string CPoolOfThreads< TRequest >::m_ThreadName
 
TThreads CStdPoolOfThreads::m_Threads
 

Friends

class CBlockingQueue_ForServer::CQueueItem::CBlockingQueue_ForServer
 
class CThreadInPool_ForServer::CAutoUnregGuard
 
class CPoolOfThreads_ForServer::CThreadInPool_ForServer
 
class CThreadPool_Task::CThreadPool_Impl
 
class CThreadPool::CThreadPool_Impl
 
class CThreadPool_Thread::CThreadPool_ThreadImpl
 
class CThreadPool_Controller::CThreadPool_Impl
 
class CBlockingQueue< TRequest >::CQueueItem::CBlockingQueue< TRequest >
 
class CThreadInPool< TRequest >::CAutoUnregGuard
 
class CPoolOfThreads< TRequest >::CThreadInPool< TRequest >
 

Detailed Description

Typedef Documentation

◆ ERunMode

template<typename TRequest >
typedef TThread::ERunMode CPoolOfThreads< TRequest >::ERunMode

Definition at line 390 of file thread_pool_old.hpp.

◆ EStatus [1/2]

Definition at line 48 of file thread_pool_for_server.hpp.

◆ EStatus [2/2]

Definition at line 551 of file thread_pool_old.hpp.

◆ TACValue [1/2]

Definition at line 272 of file thread_pool_for_server.hpp.

◆ TACValue [2/2]

template<typename TRequest >
typedef CAtomicCounter::TValue CPoolOfThreads< TRequest >::TACValue
protected

Definition at line 499 of file thread_pool_old.hpp.

◆ TCompletingHandle [1/2]

Definition at line 157 of file thread_pool_for_server.hpp.

◆ TCompletingHandle [2/2]

template<typename TRequest >
typedef CBlockingQueue<TRequest>::CCompletingHandle CThreadInPool< TRequest >::TCompletingHandle

Definition at line 311 of file thread_pool_old.hpp.

◆ TExclusiveFlags

Type of bit-masked combination of several values from EExclusiveFlags.

See also
EExclusiveFlags, RequestExclusiveExecution()

Definition at line 350 of file thread_pool.hpp.

◆ TItemHandle [1/6]

Definition at line 71 of file thread_pool_for_server.hpp.

◆ TItemHandle [2/6]

Definition at line 156 of file thread_pool_for_server.hpp.

◆ TItemHandle [3/6]

Definition at line 218 of file thread_pool_for_server.hpp.

◆ TItemHandle [4/6]

template<typename TRequest >
typedef CRef<CQueueItem> CBlockingQueue< TRequest >::TItemHandle

Definition at line 119 of file thread_pool_old.hpp.

◆ TItemHandle [5/6]

template<typename TRequest >
typedef CBlockingQueue<TRequest>::TItemHandle CThreadInPool< TRequest >::TItemHandle

Definition at line 309 of file thread_pool_old.hpp.

◆ TItemHandle [6/6]

template<typename TRequest >
typedef TQueue::TItemHandle CPoolOfThreads< TRequest >::TItemHandle

Definition at line 394 of file thread_pool_old.hpp.

◆ TKillFlags

binary OR of EKillFlags

Definition at line 637 of file thread_pool_old.hpp.

◆ TParent [1/2]

Definition at line 578 of file thread_pool_old.hpp.

◆ TParent [2/2]

Definition at line 610 of file thread_pool_old.hpp.

◆ TPool [1/2]

Definition at line 155 of file thread_pool_for_server.hpp.

◆ TPool [2/2]

template<typename TRequest >
typedef CPoolOfThreads<TRequest> CThreadInPool< TRequest >::TPool

Definition at line 308 of file thread_pool_old.hpp.

◆ TPriority [1/2]

Every request has an associated 32-bit priority field, but only the top eight bits are under direct user control.

(The rest are a counter.)

Definition at line 81 of file thread_pool_old.hpp.

◆ TPriority [2/2]

template<typename TRequest >
typedef CQueueItemBase::TPriority CBlockingQueue< TRequest >::TPriority

Definition at line 115 of file thread_pool_old.hpp.

◆ TQueue [1/2]

Definition at line 217 of file thread_pool_for_server.hpp.

◆ TQueue [2/2]

template<typename TRequest >
typedef CBlockingQueue<TRequest> CPoolOfThreads< TRequest >::TQueue

Definition at line 392 of file thread_pool_old.hpp.

◆ TQueuePredicate

template<typename TRequest >
typedef bool(CBlockingQueue::* CBlockingQueue< TRequest >::TQueuePredicate) (const TRealQueue &q) const
private

Definition at line 278 of file thread_pool_old.hpp.

◆ TRealQueue [1/2]

The type of the queue.

Definition at line 135 of file thread_pool_for_server.hpp.

◆ TRealQueue [2/2]

template<typename TRequest >
typedef set<TItemHandle, SItemHandleGreater> CBlockingQueue< TRequest >::TRealQueue
protected

The type of the queue.

Definition at line 264 of file thread_pool_old.hpp.

◆ TRequest [1/3]

Definition at line 72 of file thread_pool_for_server.hpp.

◆ TRequest [2/3]

Definition at line 158 of file thread_pool_for_server.hpp.

◆ TRequest [3/3]

Definition at line 219 of file thread_pool_for_server.hpp.

◆ TThread [1/4]

Definition at line 196 of file thread_pool_for_server.hpp.

◆ TThread [2/4]

Definition at line 215 of file thread_pool_for_server.hpp.

◆ TThread [3/4]

template<typename TRequest >
typedef CThreadInPool<TRequest> CThreadInPool< TRequest >::CAutoUnregGuard::TThread

Definition at line 364 of file thread_pool_old.hpp.

◆ TThread [4/4]

template<typename TRequest >
typedef CThreadInPool<TRequest> CPoolOfThreads< TRequest >::TThread

Definition at line 389 of file thread_pool_old.hpp.

◆ TThreads [1/2]

Definition at line 284 of file thread_pool_for_server.hpp.

◆ TThreads [2/2]

typedef list<CRef<TThread> > CStdPoolOfThreads::TThreads
private

Definition at line 675 of file thread_pool_old.hpp.

◆ TUserPriority [1/3]

Definition at line 82 of file thread_pool_old.hpp.

◆ TUserPriority [2/3]

template<typename TRequest >
typedef CQueueItemBase::TUserPriority CBlockingQueue< TRequest >::TUserPriority

Definition at line 116 of file thread_pool_old.hpp.

◆ TUserPriority [3/3]

template<typename TRequest >
typedef TQueue::TUserPriority CPoolOfThreads< TRequest >::TUserPriority

Definition at line 393 of file thread_pool_old.hpp.

Enumeration Type Documentation

◆ EErrCode

Enumerator
eControllerBusy 

attempt to create several ThreadPools with the same controller

eTaskBusy 

attempt to change task when it's already placed into ThreadPool or to put task in ThreadPool several times

eProhibited 

attempt to do something when ThreadPool was already aborted or to add task when it is prohibited by flags of exclusive execution

eInactive 

attempt to call active methods in ThreadPool_Controller when it is not attached to any ThreadPool

eInvalid 

attempt to operate task added in one ThreadPool by means of methods of another ThreadPool or invalid parameters in the constructor

Definition at line 606 of file thread_pool.hpp.

◆ EEvent

Events that can happen with ThreadPool.

Enumerator
eSuspend 

ThreadPool is suspended for exclusive task execution.

eResume 

ThreadPool is resumed after exclusive task execution.

eOther 

All other events (happen asynchronously, so cannot be further distinguished)

Definition at line 513 of file thread_pool.hpp.

◆ EExclusiveFlags

Binary flags indicating different possible options in what environment the pool will execute exclusive task.

See also
TExclusiveFlags, RequestExclusiveExecution()
Enumerator
fDoNotAllowNewTasks 

Do not allow to add new tasks to the pool during exclusive task execution.

fFlushThreads 

Finish all threads currently running in the pool.

fCancelExecutingTasks 

Cancel all currently executing tasks.

fCancelQueuedTasks 

Cancel all tasks waiting in the queue and not yet executing.

fExecuteQueuedTasks 

Execute all tasks waiting in the queue before execution of exclusive task.

Definition at line 333 of file thread_pool.hpp.

◆ EFlushType

When to start new threads after flushing old ones.

See also
FlushThreads()
Enumerator
eStartImmediately 

New threads can be started immediately.

eWaitToFinish 

New threads can be started only when all old threads finished their execution.

Definition at line 381 of file thread_pool.hpp.

◆ EKillFlags

Enumerator
fKill_Wait 

Wait for all threads in the pool to finish.

fKill_Reopen 

Allow a fresh batch of worker threads.

Definition at line 633 of file thread_pool_old.hpp.

◆ ERunMode

template<typename TRequest >
enum CThreadInPool::ERunMode

Thread run mode.

Enumerator
eNormal 

Process request and stay in the pool.

eRunOnce 

Process request and die.

Definition at line 314 of file thread_pool_old.hpp.

◆ EStatus [1/2]

Status of the task.

Enumerator
eIdle 

has not been placed in queue yet

eQueued 

in the queue, awaiting execution

eExecuting 

being executed

eCompleted 

executed successfully

eFailed 

failure during execution

eCanceled 

canceled - possible only if canceled before processing was started or if method Execute() returns result eCanceled

Definition at line 79 of file thread_pool.hpp.

◆ EStatus [2/2]

Enumerator
ePending 

still in the queue

eActive 

extracted but not yet released

eComplete 

extracted and released

eWithdrawn 

dropped by submitter's request

eForciblyCaught 

let an exception escape

Definition at line 70 of file thread_pool_old.hpp.

Function Documentation

◆ Abort()

void CThreadPool::Abort ( const CTimeSpan timeout = NULL)

Abort all functions of the pool – cancel all queued tasks, send cancellation notifications to all currently executing tasks.

Note
The already executing tasks may take some time to actually finish execution – see CancelTasks() and CThreadPool_Task::RequestToCancel()for details
Attention
This call renders the pool unusable in the sense that you must not call any of its methods after that!
Parameters
timeoutMaximum time to wait for the termination of the pooled threads. If this time is not enough for all threads to terminate, the Abort() method returns, and all threads are terminated in the background. If NULL, then wait for as long as it takes for all threads to finish.

Definition at line 2225 of file thread_pool.cpp.

References CThreadPool_Impl::Abort(), and CThreadPool::m_Impl.

Referenced by CThreadPoolEngine::ShutDown(), and CPrefetchManager::Shutdown().

◆ AcceptRequest() [1/2]

void CPoolOfThreads_ForServer::AcceptRequest ( const TRequest request)

Put a request in the queue with a given priority.

Parameters
requestA request

Definition at line 274 of file server.cpp.

References CPoolOfThreads_ForServer::m_Queue, and CBlockingQueue_ForServer::Put().

Referenced by CPoolOfThreads_ForServer::KillAllThreads(), CServer::SubmitRequest(), and CServer::x_DoRun().

◆ AcceptRequest() [2/2]

template<typename TRequest >
CPoolOfThreads< TRequest >::TItemHandle CPoolOfThreads< TRequest >::AcceptRequest ( const TRequest &  request,
TUserPriority  priority = 0,
unsigned int  timeout_sec = 0,
unsigned int  timeout_nsec = 0 
)
inline

Put a request in the queue with a given priority.

Parameters
requestA request
priorityThe priority of the request. The higher the priority the sooner the request will be processed.

Definition at line 1093 of file thread_pool_old.hpp.

Referenced by CMainLoopThread::Main(), and SGridWorkerNodeImpl::OfflineRun().

◆ AcceptUrgentRequest()

template<typename TRequest >
CPoolOfThreads< TRequest >::TItemHandle CPoolOfThreads< TRequest >::AcceptUrgentRequest ( const TRequest &  request,
unsigned int  timeout_sec = 0,
unsigned int  timeout_nsec = 0 
)
inline

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.

Parameters
requestA request

Definition at line 1104 of file thread_pool_old.hpp.

◆ AddTask()

void CThreadPool::AddTask ( CThreadPool_Task task,
const CTimeSpan timeout = NULL 
)

Add task to the pool for execution.

Note
The pool will acquire a CRef ownership to the task which it will hold until the task goes out of the pool (when finished)
Parameters
taskTask to add
timeoutTime to wait if the tasks queue has reached its maximum length. If NULL, then wait indefinitely.

Definition at line 2213 of file thread_pool.cpp.

References CThreadPool_Impl::AddTask(), and CThreadPool::m_Impl.

Referenced by CPrefetchManager_Impl::AddAction(), CPSG_TaskGroup::AddTask(), CBamUtils::CreateCoverageGraphs(), and CThreadPoolEngine::StartJob().

◆ CancelTask()

void CThreadPool::CancelTask ( CThreadPool_Task task)

Request to cancel the task and remove it from queue if it is there.

See also
CThreadPool_Task::RequestToCancel()

Definition at line 2219 of file thread_pool.cpp.

References CThreadPool_Impl::CancelTask(), and CThreadPool::m_Impl.

Referenced by CThreadPoolEngine::CancelJob().

◆ CancelTasks()

void CThreadPool::CancelTasks ( TExclusiveFlags  tasks_group)

Cancel the selected groups of tasks in the pool.

Parameters
tasks_groupMust be a combination of fCancelQueuedTasks and/or fCancelExecutingTasks. Cannot be zero.

Definition at line 2256 of file thread_pool.cpp.

References CThreadPool_Impl::CancelTasks(), and CThreadPool::m_Impl.

Referenced by CPrefetchManager::CancelAllTasks(), CBamUtils::CreateCoverageGraphs(), and CThreadPoolEngine::RequestCancel().

◆ CAutoUnregGuard() [1/2]

CThreadInPool_ForServer::CAutoUnregGuard::CAutoUnregGuard ( TThread thr)

Definition at line 154 of file server.cpp.

◆ CAutoUnregGuard() [2/2]

template<typename TRequest >
CThreadInPool< TRequest >::CAutoUnregGuard::CAutoUnregGuard ( TThread thr)

Definition at line 942 of file thread_pool_old.hpp.

◆ CBlockingQueue() [1/2]

template<typename TRequest >
CBlockingQueue< TRequest >::CBlockingQueue ( const CBlockingQueue< TRequest > &  )
private

forbidden

◆ CBlockingQueue() [2/2]

template<typename TRequest >
CBlockingQueue< TRequest >::CBlockingQueue ( size_t  max_size = kMax_UInt)
inline

Constructor.

Parameters
max_sizeThe maximum size of the queue (may not be zero!)

Definition at line 142 of file thread_pool_old.hpp.

◆ CBlockingQueue_ForServer() [1/2]

CBlockingQueue_ForServer::CBlockingQueue_ForServer ( const CBlockingQueue_ForServer )
private

forbidden

◆ CBlockingQueue_ForServer() [2/2]

CBlockingQueue_ForServer::CBlockingQueue_ForServer ( void  )
inline

Constructor.

Definition at line 93 of file thread_pool_for_server.hpp.

◆ CCompletingHandle() [1/2]

CBlockingQueue_ForServer::CCompletingHandle::CCompletingHandle ( const TItemHandle h)
inline

Definition at line 80 of file thread_pool_for_server.hpp.

◆ CCompletingHandle() [2/2]

template<typename TRequest >
CBlockingQueue< TRequest >::CCompletingHandle::CCompletingHandle ( const TItemHandle h)
inline

Definition at line 127 of file thread_pool_old.hpp.

◆ CountSelf() [1/2]

template<typename TRequest >
void CThreadInPool< TRequest >::CountSelf ( CAtomicCounter counter)

Definition at line 926 of file thread_pool_old.hpp.

References _ASSERT, CAtomicCounter::Add(), and NULL.

◆ CountSelf() [2/2]

void CThreadInPool_ForServer::CountSelf ( void  )

◆ CPoolOfThreads()

template<typename TRequest >
CPoolOfThreads< TRequest >::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.

Parameters
max_threadsThe maximum number of threads that this pool can run
queue_sizeThe maximum number of requests in the queue
spawn_threasholdThe number of requests in the queue after which a new thread is started
max_urgent_threadsThe maximum number of urgent threads running simultaneously

Definition at line 1055 of file thread_pool_old.hpp.

◆ CPoolOfThreads_ForServer()

CPoolOfThreads_ForServer::CPoolOfThreads_ForServer ( unsigned int  max_threads,
const string thr_suffix 
)

Constructor.

Parameters
max_threadsThe maximum number of threads that this pool can run

Definition at line 239 of file server.cpp.

References CPoolOfThreads_ForServer::m_ThreadCount, and CAtomicCounter::Set().

◆ CQueueItem() [1/2]

CBlockingQueue_ForServer::CQueueItem::CQueueItem ( TRequest  request)
inline

Definition at line 112 of file thread_pool_for_server.hpp.

◆ CQueueItem() [2/2]

template<typename TRequest >
CBlockingQueue< TRequest >::CQueueItem::CQueueItem ( Uint4  priority,
TRequest  request 
)
inline

Definition at line 235 of file thread_pool_old.hpp.

◆ CQueueItemBase()

CQueueItemBase::CQueueItemBase ( TPriority  priority)
inline

Definition at line 84 of file thread_pool_old.hpp.

◆ CQueueItemBase_ForServer()

CQueueItemBase_ForServer::CQueueItemBase_ForServer ( void  )
inline

Definition at line 50 of file thread_pool_for_server.hpp.

◆ CreateThread()

CThreadPool_Thread * CThreadPool::CreateThread ( void  )
protectedvirtual

Create new thread for the pool.

Definition at line 2207 of file thread_pool.cpp.

References CThreadPool_ThreadImpl::s_CreateThread().

Referenced by CThreadPool_Impl::LaunchThreads().

◆ CStdPoolOfThreads()

CStdPoolOfThreads::CStdPoolOfThreads ( 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 
)
inline

Constructor.

Parameters
max_threadsThe maximum number of threads that this pool can run
queue_sizeThe maximum number of requests in the queue
spawn_thresholdThe number of requests in the queue after which a new thread is started
max_urgent_threadsThe maximum number of urgent threads running simultaneously

Definition at line 623 of file thread_pool_old.hpp.

◆ CStdThreadInPool()

CStdThreadInPool::CStdThreadInPool ( TPool pool,
ERunMode  mode = eNormal 
)
inline

Constructor.

Parameters
poolA pool where this thead is placed
modeA running mode of this thread

Definition at line 586 of file thread_pool_old.hpp.

◆ CThreadInPool()

template<typename TRequest >
CThreadInPool< TRequest >::CThreadInPool ( TPool pool,
ERunMode  mode = eNormal 
)
inline

Constructor.

Parameters
poolA pool where this thead is placed
modeA running mode of this thread

Definition at line 325 of file thread_pool_old.hpp.

◆ CThreadInPool_ForServer()

CThreadInPool_ForServer::CThreadInPool_ForServer ( TPool pool)
inline

Constructor.

Parameters
poolA pool where this thead is placed
modeA running mode of this thread

Definition at line 166 of file thread_pool_for_server.hpp.

◆ CThreadPool() [1/3]

CThreadPool::CThreadPool ( const CThreadPool )
private

Prohibit copying and assigning.

◆ CThreadPool() [2/3]

CThreadPool::CThreadPool ( unsigned int  queue_size,
CThreadPool_Controller controller,
CThread::TRunMode  threads_mode = CThread::fRunDefault 
)

Constructor with custom controller.

Parameters
queue_sizeMaximum number of tasks waiting in the queue. If 0 then tasks cannot be queued and are added only when there are threads to process them. If greater than 0 and there will be attempt to add new task over this maximum then method AddTask() will wait for the given timeout for some empty space in the queue.
controllerCustom controller object that will be responsible for number of threads in the pool, when new threads have to be launched and old and unused threads have to be finished. Default controller implementation (set for the pool in case of using other constructor) is CThreadPool_Controller_PID class.
threads_modeRunning mode of all threads in thread pool. Values fRunDetached and fRunAllowST are ignored.

Definition at line 2187 of file thread_pool.cpp.

References CThreadPool::CThreadPool_Impl, CThreadPool::m_Impl, and CThreadPool_Impl::SetInterfaceStarted().

◆ CThreadPool() [3/3]

CThreadPool::CThreadPool ( unsigned int  queue_size,
unsigned int  max_threads,
unsigned int  min_threads = 2,
CThread::TRunMode  threads_mode = CThread::fRunDefault 
)

Constructor.

Parameters
queue_sizeMaximum number of tasks waiting in the queue. If 0 then tasks cannot be queued and are added only when there are threads to process them. If greater than 0 and there will be attempt to add new task over this maximum then method AddTask() will wait for the given timeout for some empty space in the queue.
max_threadsMaximum number of threads allowed to be launched in the pool. Value cannot be less than min_threads or equal to 0.
min_threadsMinimum number of threads that have to be launched even if there are no tasks added. Value cannot be greater than max_threads.
threads_modeRunning mode of all threads in thread pool. Values fRunDetached and fRunAllowST are ignored.
See also
AddTask()

Definition at line 2177 of file thread_pool.cpp.

References CThreadPool::CThreadPool_Impl, CThreadPool::m_Impl, and CThreadPool_Impl::SetInterfaceStarted().

◆ CThreadPool_Controller() [1/2]

CThreadPool_Controller::CThreadPool_Controller ( const CThreadPool_Controller )
private

Prohibit copying and assigning.

◆ CThreadPool_Controller() [2/2]

CThreadPool_Controller::CThreadPool_Controller ( unsigned int  max_threads,
unsigned int  min_threads 
)

Constructor.

Parameters
max_threadsMaximum number of threads in pool
min_threadsMinimum number of threads in pool

Definition at line 1995 of file thread_pool.cpp.

References NCBI_THROW_FMT.

◆ CThreadPool_Controller_PID()

CThreadPool_Controller_PID::CThreadPool_Controller_PID ( unsigned int  max_threads,
unsigned int  min_threads 
)

Constructor.

Parameters
max_threadsMaximum number of threads in pool
min_threadsMinimum number of threads in pool

Definition at line 40 of file thread_pool_ctrl.cpp.

References eStart, and CThreadPool_Controller_PID::m_ErrHistory.

◆ CThreadPool_Task() [1/2]

CThreadPool_Task::CThreadPool_Task ( const CThreadPool_Task other)
protected

Copy ctor.

Definition at line 946 of file thread_pool.cpp.

References CThreadPool_Task::m_Priority, and CThreadPool_Task::x_Init().

◆ CThreadPool_Task() [2/2]

CThreadPool_Task::CThreadPool_Task ( unsigned int  priority = 0)

Constructor.

Parameters
priorityPriority of the task - the smaller the priority, the sooner the task will execute

Definition at line 941 of file thread_pool.cpp.

References CThreadPool_Task::x_Init().

◆ CThreadPool_Thread() [1/2]

CThreadPool_Thread::CThreadPool_Thread ( const CThreadPool_Thread )
private

Prohibit copying and assigning.

◆ CThreadPool_Thread() [2/2]

CThreadPool_Thread::CThreadPool_Thread ( CThreadPool pool)
protected

Construct and attach to the pool.

Definition at line 2129 of file thread_pool.cpp.

References _ASSERT, CThreadPool_Thread::CThreadPool_ThreadImpl, CThreadPool_Thread::m_Impl, and CThreadPool_Impl::s_GetImplPointer().

◆ EnsureLimits()

void CThreadPool_Controller::EnsureLimits ( void  )
protected

◆ Execute()

virtual EStatus CThreadPool_Task::Execute ( void  )
pure virtual

◆ Finalize()

void CThreadPool_Thread::Finalize ( void  )
protectedvirtual

Clean up. It is called by OnExit()

Definition at line 2147 of file thread_pool.cpp.

Referenced by CThreadPool_ThreadImpl::OnExit().

◆ FlushThreads()

void CThreadPool::FlushThreads ( EFlushType  flush_type)

Finish all current threads and replace them with new ones.

Parameters
flush_typeIf new threads can be launched immediately after call to this method or only after all "old" threads have been finished.

Definition at line 2262 of file thread_pool.cpp.

References CThreadPool_Impl::FlushThreads(), and CThreadPool::m_Impl.

◆ Get()

template<typename TRequest >
TRequest CBlockingQueue< TRequest >::Get ( unsigned int  timeout_sec = kMax_UInt,
unsigned int  timeout_nsec = 0 
)

Get the first available request from the queue, and return just the request.

Blocks politely if empty. Waits up to timeout_sec + timeout_nsec/1E9 seconds.

Parameters
timeout_secNumber of seconds
timeout_nsecNumber of nanoseconds

Definition at line 815 of file thread_pool_old.hpp.

◆ GetChangeCalcTime()

double CThreadPool_Controller_PID::GetChangeCalcTime ( void  )
inline

Get the time period for which average speed of changing of waiting tasks number is calculated.

Definition at line 217 of file thread_pool_ctrl.hpp.

References CThreadPool_Controller_PID::m_DerivTime.

◆ GetChangePredictTime()

double CThreadPool_Controller_PID::GetChangePredictTime ( void  )
inline

Get period of prediction of number of tasks in queue.

See also
SetChangePredictTime()

Definition at line 229 of file thread_pool_ctrl.hpp.

References CThreadPool_Controller_PID::m_DerivCoeff.

◆ GetCurrentTask()

CRef< CThreadPool_Task > CThreadPool_Thread::GetCurrentTask ( void  ) const

Get the task currently executing in the thread.

Definition at line 2157 of file thread_pool.cpp.

References CThreadPool_ThreadImpl::GetCurrentTask(), and CThreadPool_Thread::m_Impl.

Referenced by CPrefetchManager::IsActive().

◆ GetDestroyTimeout()

const CTimeSpan & CThreadPool::GetDestroyTimeout ( void  ) const

Get timeout to wait for all threads to finish before the pool will be able to destroy.

Note
This method is meant to be called very rarely. Because of that it is implemented in non-threadsafe manner. While this method is working (and after that if timeout is stored in some variable as reference) it is not allowed to call SetDestroyTimeout() in other threads.

Definition at line 2243 of file thread_pool.cpp.

References CThreadPool_Impl::GetDestroyTimeout(), and CThreadPool::m_Impl.

◆ GetErrCodeString()

const char * CThreadPoolException::GetErrCodeString ( void  ) const
overridevirtual

◆ GetExecutingTasksCount()

unsigned int CThreadPool::GetExecutingTasksCount ( void  ) const

Get the number of currently executing tasks.

Definition at line 2280 of file thread_pool.cpp.

References CThreadPool_Impl::GetExecutingTasksCount(), and CThreadPool::m_Impl.

Referenced by CBamUtils::CreateCoverageGraphs(), and CThreadPool_Controller_PID::OnEvent().

◆ GetHandle() [1/3]

template<typename TRequest >
CBlockingQueue< TRequest >::TItemHandle CBlockingQueue< TRequest >::GetHandle ( unsigned int  timeout_sec = kMax_UInt,
unsigned int  timeout_nsec = 0 
)

Get the first available request from the queue, and return a handle to it.

Blocks politely if empty. Waits up to timeout_sec + timeout_nsec/1E9 seconds.

Parameters
timeout_secNumber of seconds
timeout_nsecNumber of nanoseconds

Definition at line 767 of file thread_pool_old.hpp.

References _VERIFY, set< Key, Compare >::begin(), set< Key, Compare >::empty(), set< Key, Compare >::erase(), NCBI_THROW, ok, CGuard< Resource, Lock, Unlock, ReportExceptions >::Release(), set< Key, Compare >::size(), and CBlockingQueue< TRequest >::x_GetSemPred().

Referenced by CSeqFetchQueue::Clear(), and CThreadInPool< TRequest >::x_HandleOneRequest().

◆ GetHandle() [2/3]

CBlockingQueue_ForServer::TItemHandle CBlockingQueue_ForServer::GetHandle ( void  )

◆ GetHandle() [3/3]

CPoolOfThreads_ForServer::TItemHandle CPoolOfThreads_ForServer::GetHandle ( void  )

◆ GetHunger()

template<typename TRequest >
size_t CBlockingQueue< TRequest >::GetHunger ( void  ) const
inline

Get the number of threads waiting for requests, for debugging purposes only.

Definition at line 229 of file thread_pool_old.hpp.

◆ GetMainPoolMutex() [1/2]

CMutex & CThreadPool_Controller::GetMainPoolMutex ( CThreadPool pool) const
protected

Get mutex which guards access to pool All work in controller should be based on the same mutex as in pool.

So every time when you need to guard access to some members of derived class it is recommended to use this very mutex. But NB: it's assumed everywhere that this mutex is locked on the small periods of time. So be careful and implement the same pattern.

Definition at line 2021 of file thread_pool.cpp.

References NCBI_THROW, and CThreadPool_Impl::s_GetImplPointer().

Referenced by CThreadPool_Controller_PID::GetSafeSleepTime().

◆ GetMainPoolMutex() [2/2]

CMutex & CThreadPool::GetMainPoolMutex ( void  )
protected

Get the mutex that protects all changes in the pool.

Definition at line 2201 of file thread_pool.cpp.

References CThreadPool_Impl::GetMainPoolMutex(), and CThreadPool::m_Impl.

◆ GetMaxSize()

template<typename TRequest >
size_t CBlockingQueue< TRequest >::GetMaxSize ( void  ) const
inline

Get the maximun number of requests that can be put into the queue.

Definition at line 213 of file thread_pool_old.hpp.

Referenced by CBlockingQueue< CRef< CStdRequest > >::IsFull().

◆ GetMaxThreads()

unsigned int CThreadPool_Controller::GetMaxThreads ( void  ) const
inline

◆ GetMinThreads()

unsigned int CThreadPool_Controller::GetMinThreads ( void  ) const
inline

◆ GetPool() [1/3]

CThreadPool * CThreadPool_Task::GetPool ( void  ) const
protected

The thread pool which accepted this task for execution.

See also
CThreadPool::AddTask()

Definition at line 1063 of file thread_pool.cpp.

References CThreadPool_Impl::GetPoolInterface(), CThreadPool_Task::m_Pool, and NULL.

Referenced by CThreadPool_Impl::CancelTask().

◆ GetPool() [2/3]

CThreadPool * CThreadPool_Thread::GetPool ( void  ) const
protected

Get the thread pool in which this thread is running.

Definition at line 2151 of file thread_pool.cpp.

References CThreadPool_ThreadImpl::GetPool(), and CThreadPool_Thread::m_Impl.

◆ GetPool() [3/3]

CThreadPool * CThreadPool_Controller::GetPool ( void  ) const
protected

◆ GetPriority() [1/2]

unsigned int CThreadPool_Task::GetPriority ( void  ) const
inline

Get priority of the task.

Definition at line 651 of file thread_pool.hpp.

References CThreadPool_Task::m_Priority.

Referenced by SThreadPool_TaskCompare::operator()().

◆ GetPriority() [2/2]

const TPriority& CQueueItemBase::GetPriority ( void  ) const
inline

Definition at line 91 of file thread_pool_old.hpp.

References CQueueItemBase::m_Priority.

◆ GetQueuedTasksCount()

unsigned int CThreadPool::GetQueuedTasksCount ( void  ) const

Get the number of tasks currently waiting in queue.

Definition at line 2274 of file thread_pool.cpp.

References CThreadPool_Impl::GetQueuedTasksCount(), and CThreadPool::m_Impl.

Referenced by CBamUtils::CreateCoverageGraphs(), and CThreadPool_Controller_PID::OnEvent().

◆ GetQueuedTasksThreshold()

double CThreadPool_Controller_PID::GetQueuedTasksThreshold ( void  )
inline

Get maximum number of tasks in queue per each thread.

See also
SetQueuedTasksThreshold()

Definition at line 193 of file thread_pool_ctrl.hpp.

References CThreadPool_Controller_PID::m_Threshold.

◆ GetQueueSize()

template<typename TRequest >
size_t CPoolOfThreads< TRequest >::GetQueueSize ( void  ) const
inline

Get the number of requests in the queue.

Definition at line 473 of file thread_pool_old.hpp.

◆ GetRequest() [1/2]

const TRequest& CBlockingQueue_ForServer::CQueueItem::GetRequest ( void  ) const
inline

◆ GetRequest() [2/2]

template<typename TRequest >
const TRequest& CBlockingQueue< TRequest >::CQueueItem::GetRequest ( void  ) const
inline

Definition at line 239 of file thread_pool_old.hpp.

◆ GetRunMode()

template<typename TRequest >
ERunMode CThreadInPool< TRequest >::GetRunMode ( void  ) const
inlineprotected

Get run mode.

Definition at line 351 of file thread_pool_old.hpp.

◆ GetSafeSleepTime() [1/2]

CTimeSpan CThreadPool_Controller::GetSafeSleepTime ( void  ) const
virtual

Get maximum timeout for which calls to method HandleEvent() can be missing.

Method HandleEvent() will be called after this timeout for sure if ThreadPool will not be aborted or in suspended state at this moment.

Reimplemented in CThreadPool_Controller_PID.

Definition at line 2117 of file thread_pool.cpp.

References CThreadPool_Controller::m_Pool.

Referenced by CThreadPool_Controller_PID::GetSafeSleepTime(), and CThreadPool_Impl::GetSafeSleepTime().

◆ GetSafeSleepTime() [2/2]

CTimeSpan CThreadPool_Controller_PID::GetSafeSleepTime ( void  ) const
virtual

◆ GetSize()

template<typename TRequest >
size_t CBlockingQueue< TRequest >::GetSize ( void  ) const

◆ GetStatus() [1/3]

const EStatus& CQueueItemBase_ForServer::GetStatus ( void  ) const
inline

◆ GetStatus() [2/3]

CThreadPool_Task::EStatus CThreadPool_Task::GetStatus ( void  ) const
inline

◆ GetStatus() [3/3]

const EStatus& CQueueItemBase::GetStatus ( void  ) const
inline

Definition at line 92 of file thread_pool_old.hpp.

References CQueueItemBase::m_Status.

◆ GetTaskMaxQueuedTime()

double CThreadPool_Controller_PID::GetTaskMaxQueuedTime ( void  )
inline

Get maximum time that task can wait in queue for processing until new thread will be launched.

See also
SetTaskMaxQueuedTime()

Definition at line 205 of file thread_pool_ctrl.hpp.

References CThreadPool_Controller_PID::m_IntegrCoeff.

◆ GetThreadsCount()

unsigned int CThreadPool::GetThreadsCount ( void  ) const

Get total number of threads currently running in pool.

Definition at line 2268 of file thread_pool.cpp.

References CThreadPool_Impl::GetThreadsCount(), and CThreadPool::m_Impl.

Referenced by CThreadPool_Controller_PID::GetSafeSleepTime(), and CThreadPool_Controller_PID::OnEvent().

◆ GetUserPriority()

TUserPriority CQueueItemBase::GetUserPriority ( void  ) const
inline

Definition at line 93 of file thread_pool_old.hpp.

References CQueueItemBase::m_Priority.

◆ HandleEvent()

void CThreadPool_Controller::HandleEvent ( EEvent  event)

This method is called every time something happens in a pool, such as: new task added, task is started or finished execution, new threads started or some threads finished.

It does the hardcoded must-do processing of the event, and also calls OnEvent() callback to run the controlling algorithm. Method ensures that OnEvent() always called protected with ThreadPool main mutex and that ThreadPool itself is not aborted or in suspended for exclusive execution state (except the eSuspend event).

See also
OnEvent()

Definition at line 2093 of file thread_pool.cpp.

References CThreadPool_Impl::IsAborted(), CThreadPool_Impl::IsSuspended(), CThreadPool_Controller::m_InHandleEvent, CThreadPool_Controller::m_Pool, and CThreadPool_Controller::OnEvent().

Referenced by CThreadPool_Impl::CallController().

◆ HasImmediateRoom()

template<typename TRequest >
bool CPoolOfThreads< TRequest >::HasImmediateRoom ( bool  urgent = false) const
inline

Check whether a new request could be immediately processed.

Parameters
urgentWhether the request would be urgent.

Definition at line 1113 of file thread_pool_old.hpp.

References ERR_POST_XX, and m_MaxThreads.

◆ Init()

template<typename TRequest >
virtual void CThreadInPool< TRequest >::Init ( void  )
inlineprotectedvirtual

Intit this thread. It is called at beginning of Main()

Definition at line 335 of file thread_pool_old.hpp.

Referenced by CThreadInPool< TRequest >::Main().

◆ Initialize()

void CThreadPool_Thread::Initialize ( void  )
protectedvirtual

Init this thread. It is called at beginning of Main()

Definition at line 2143 of file thread_pool.cpp.

Referenced by CThreadPool_ThreadImpl::Main().

◆ IsAborted()

bool CThreadPool::IsAborted ( void  ) const

Does method Abort() was already called for this ThreadPool.

Definition at line 2231 of file thread_pool.cpp.

References CThreadPool_Impl::IsAborted(), and CThreadPool::m_Impl.

Referenced by CPrefetchManager_Impl::AddAction().

◆ IsCancelRequested()

bool CThreadPool_Task::IsCancelRequested ( void  ) const
inline

◆ IsEmpty() [1/2]

template<typename TRequest >
bool CBlockingQueue< TRequest >::IsEmpty ( void  ) const
inline

Check if the queue is empty.

Definition at line 216 of file thread_pool_old.hpp.

Referenced by CSeqFetchQueue::IsEmpty(), and CPoolOfThreads< CRef< CStdRequest > >::IsEmpty().

◆ IsEmpty() [2/2]

template<typename TRequest >
bool CPoolOfThreads< TRequest >::IsEmpty ( void  ) const
inline

Check if the queue is empty.

Definition at line 457 of file thread_pool_old.hpp.

Referenced by SGridWorkerNodeImpl::OfflineRun().

◆ IsFinished()

bool CThreadPool_Task::IsFinished ( void  ) const
inline

Check if task execution has been already finished (successfully or not)

Definition at line 645 of file thread_pool.hpp.

References CThreadPool_Task::eCompleted, and CThreadPool_Task::m_Status.

Referenced by CThreadPool_Impl::CancelTask(), CPrefetchRequest::IsDone(), CThreadPool_Task::RequestToCancel(), and CThreadPool_Task::x_SetStatus().

◆ IsFull() [1/2]

template<typename TRequest >
bool CBlockingQueue< TRequest >::IsFull ( void  ) const
inline

Check if the queue is full.

Definition at line 219 of file thread_pool_old.hpp.

Referenced by CSeqFetchQueue::IsFull(), and CPoolOfThreads< CRef< CStdRequest > >::IsFull().

◆ IsFull() [2/2]

template<typename TRequest >
bool CPoolOfThreads< TRequest >::IsFull ( void  ) const
inline

Check if the queue is full.

Definition at line 454 of file thread_pool_old.hpp.

◆ KillAllThreads() [1/3]

void CPoolOfThreads_ForServer::KillAllThreads ( bool  wait)

Causes all threads in the pool to exit cleanly after finishing all pending requests, optionally waiting for them to die.

Parameters
waitIf true will wait until all thread in the pool finish their job

Definition at line 294 of file server.cpp.

References CPoolOfThreads_ForServer::AcceptRequest(), i, CPoolOfThreads_ForServer::m_KilledAll, CPoolOfThreads_ForServer::m_MaxThreads, CPoolOfThreads_ForServer::m_Threads, and NON_CONST_ITERATE.

Referenced by CServer::Run(), and CPoolOfThreads_ForServer::~CPoolOfThreads_ForServer().

◆ KillAllThreads() [2/3]

virtual void CStdPoolOfThreads::KillAllThreads ( bool  wait)
inlinevirtual

Causes all threads in the pool to exit cleanly after finishing all pending requests, optionally waiting for them to die.

Parameters
waitIf true will wait until all thread in the pool finish their job

Definition at line 651 of file thread_pool_old.hpp.

References CStdPoolOfThreads::fKill_Reopen, CStdPoolOfThreads::fKill_Wait, and CStdPoolOfThreads::KillAllThreads().

◆ KillAllThreads() [3/3]

void CStdPoolOfThreads::KillAllThreads ( TKillFlags  flags)
virtual

◆ Main() [1/3]

void * CThreadInPool_ForServer::Main ( void  )
privatevirtual

◆ Main() [2/3]

void * CThreadPool_Thread::Main ( void  )
privatevirtual

To prevent overriding - main thread function.

Implements CThread.

Definition at line 2163 of file thread_pool.cpp.

References CThreadPool_Thread::m_Impl, CThreadPool_ThreadImpl::Main(), and NULL.

◆ Main() [3/3]

template<typename TRequest >
void * CThreadInPool< TRequest >::Main ( void  )
privatevirtual

◆ MarkAsComplete() [1/2]

void CQueueItemBase_ForServer::MarkAsComplete ( void  )
inline

◆ MarkAsComplete() [2/2]

void CQueueItemBase::MarkAsComplete ( void  )
inline

Definition at line 95 of file thread_pool_old.hpp.

References CQueueItemBase::eComplete, and CQueueItemBase::x_SetStatus().

◆ MarkAsForciblyCaught() [1/2]

void CQueueItemBase_ForServer::MarkAsForciblyCaught ( void  )
inline

◆ MarkAsForciblyCaught() [2/2]

void CQueueItemBase::MarkAsForciblyCaught ( void  )
inline

◆ NCBI_EXCEPTION_DEFAULT()

CThreadPoolException::NCBI_EXCEPTION_DEFAULT ( CThreadPoolException  ,
CException   
)

◆ NCBI_PARAM_DECL()

NCBI_PARAM_DECL ( bool  ,
ThreadPool  ,
Catch_Unhandled_Exceptions   
)

◆ NCBI_PARAM_TYPE()

typedef NCBI_PARAM_TYPE ( ThreadPool  ,
Catch_Unhandled_Exceptions   
)

◆ NewThread() [1/3]

template<typename TRequest >
virtual TThread* CPoolOfThreads< TRequest >::NewThread ( ERunMode  mode)
protectedpure virtual

Create a new thread.

Parameters
modeHow long the thread should stay around

Implemented in CStdPoolOfThreads.

◆ NewThread() [2/3]

virtual TThread* CStdPoolOfThreads::NewThread ( TThread::ERunMode  mode)
inlineprotectedvirtual

Create a new thread.

Parameters
modeA thread's running mode

Implements CPoolOfThreads< CRef< CStdRequest > >.

Definition at line 671 of file thread_pool_old.hpp.

◆ NewThread() [3/3]

TThread* CPoolOfThreads_ForServer::NewThread ( void  )
inlineprivate

Create a new thread.

Definition at line 254 of file thread_pool_for_server.hpp.

References CPoolOfThreads_ForServer::CThreadInPool_ForServer.

Referenced by CPoolOfThreads_ForServer::Spawn().

◆ OnCancelRequested()

void CThreadPool_Task::OnCancelRequested ( void  )
protectedvirtual

Callback to notify when cancellation of the task is requested.

See also
OnStatusChange()

Definition at line 987 of file thread_pool.cpp.

Referenced by CThreadPool_Task::x_RequestToCancel().

◆ OnEvent() [1/2]

void CThreadPool_Controller_PID::OnEvent ( EEvent  event)
protectedvirtual

◆ OnEvent() [2/2]

virtual void CThreadPool_Controller::OnEvent ( EEvent  event)
protectedpure virtual

Main method for the implementation of controlling algorithm.

Method should not implement any excessive calculations because it will be called guarded with main pool mutex and because of that it will block several important pool operations.

Note
Method will never be called recursively or concurrently in different threads (HandleEvent() will take care of this).
See also
HandleEvent()

Implemented in CPSGS_ThreadPool_Controller, and CThreadPool_Controller_PID.

Referenced by CThreadPool_Controller::HandleEvent().

◆ OnExit() [1/2]

void CThreadPool_Thread::OnExit ( void  )
privatevirtual

To prevent overriding - do cleanup after exiting from thread.

Reimplemented from CThread.

Definition at line 2170 of file thread_pool.cpp.

References CThreadPool_Thread::m_Impl, and CThreadPool_ThreadImpl::OnExit().

◆ OnExit() [2/2]

template<typename TRequest >
void CThreadInPool< TRequest >::OnExit ( void  )
privatevirtual

Override this to execute finalization code.

Unlike destructor, this code will be executed before thread termination and as a part of the thread.

Reimplemented from CThread.

Definition at line 1035 of file thread_pool_old.hpp.

References STD_CATCH_ALL_XX, and CThreadInPool< TRequest >::x_OnExit().

◆ OnStatusChange() [1/2]

void CThreadPool_Task::OnStatusChange ( EStatus  old)
protectedvirtual

Callback to notify on changes in the task status.

Parameters
oldTask status before the change. Current value can be obtained from GetStatus().
Note
Status eQueued is set before task is actually pushed to the queue. After eQueued status eIdle can appear if insertion into the queue failed because of timeout. Status eCanceled will be set only in 2 cases:
See also
OnCancelRequested(), IsCancelRequested(), GetStatus()

Reimplemented in CPrefetchRequest.

Definition at line 983 of file thread_pool.cpp.

Referenced by CThreadPool_Task::x_SetStatus().

◆ OnStatusChange() [2/2]

virtual void CStdRequest::OnStatusChange ( EStatus  ,
EStatus   
)
inlinevirtual

Callback for status changes.

Definition at line 554 of file thread_pool_old.hpp.

Referenced by CBlockingQueue_ForServer::CQueueItem::x_SetStatus().

◆ operator()()

template<typename TRequest >
bool CBlockingQueue< TRequest >::SItemHandleGreater::operator() ( const TItemHandle i1,
const TItemHandle i2 
) const
inline

Definition at line 258 of file thread_pool_old.hpp.

◆ operator=() [1/6]

template<typename TRequest >
CBlockingQueue& CBlockingQueue< TRequest >::operator= ( const CBlockingQueue< TRequest > &  )
private

◆ operator=() [2/6]

CBlockingQueue_ForServer& CBlockingQueue_ForServer::operator= ( const CBlockingQueue_ForServer )
private

◆ operator=() [3/6]

CThreadPool& CThreadPool::operator= ( const CThreadPool )
private

◆ operator=() [4/6]

CThreadPool_Controller& CThreadPool_Controller::operator= ( const CThreadPool_Controller )
private

◆ operator=() [5/6]

CThreadPool_Task & CThreadPool_Task::operator= ( const CThreadPool_Task other)
protected

Assignment.

Note
There is a possible race condition if request is assigned and added to the pool at the same time by different threads. It is a responsibility of the derived class to avoid this race.

Definition at line 966 of file thread_pool.cpp.

References CAtomicCounter::Get(), CThreadPool_Task::m_IsBusy, CThreadPool_Task::m_Priority, NCBI_THROW, and CObject::operator=().

◆ operator=() [6/6]

CThreadPool_Thread& CThreadPool_Thread::operator= ( const CThreadPool_Thread )
private

◆ operator>()

bool CQueueItemBase::operator> ( const CQueueItemBase item) const
inline

Definition at line 88 of file thread_pool_old.hpp.

References CQueueItemBase::m_Priority.

◆ Process()

virtual void CStdRequest::Process ( void  )
pure virtual

◆ ProcessRequest() [1/6]

virtual void CStdThreadInPool::ProcessRequest ( const CRef< CStdRequest > &  req)
inlineprotectedvirtual

Process a request.

Parameters
Arequest for processing

Implements CThreadInPool< CRef< CStdRequest > >.

Definition at line 594 of file thread_pool_old.hpp.

References CStdRequest::Process().

◆ ProcessRequest() [2/6]

void CThreadInPool_ForServer::ProcessRequest ( const TRequest req)
inlineprotected

Older interface (still delegated to by default)

Definition at line 183 of file thread_pool_for_server.hpp.

References CRef< C, Locker >::GetNCPointerOrNull(), and CStdRequest::Process().

◆ ProcessRequest() [3/6]

template<typename TRequest >
virtual void CThreadInPool< TRequest >::ProcessRequest ( const TRequest &  req)
protectedpure virtual

Older interface (still delegated to by default)

Implemented in CStdThreadInPool.

◆ ProcessRequest() [4/6]

void CThreadInPool_ForServer::ProcessRequest ( TItemHandle  handle)
protected

Process a request.

It is called from Main() for each request this thread handles

Parameters
Arequest for processing

Definition at line 232 of file server.cpp.

Referenced by CThreadInPool_ForServer::x_HandleOneRequest().

◆ ProcessRequest() [5/6]

template<typename TRequest >
void CThreadInPool< TRequest >::ProcessRequest ( TItemHandle  handle)
protectedvirtual

Process a request.

It is called from Main() for each request this thread handles

Parameters
Arequest for processing

Definition at line 1043 of file thread_pool_old.hpp.

Referenced by CThreadInPool< TRequest >::x_HandleOneRequest().

◆ ProcessRequest() [6/6]

virtual void CStdThreadInPool::ProcessRequest ( TItemHandle  handle)
inlineprotectedvirtual

◆ Put() [1/2]

CBlockingQueue_ForServer::TItemHandle CBlockingQueue_ForServer::Put ( const TRequest request)

Put a request into the queue.

If the queue remains full for the duration of the (optional) timeout, throw an exception.

Parameters
requestRequest

Definition at line 125 of file server.cpp.

References data, CBlockingQueue_ForServer::m_GetCond, CBlockingQueue_ForServer::m_Mutex, CBlockingQueue_ForServer::m_Queue, and CConditionVariable::SignalAll().

Referenced by CPoolOfThreads_ForServer::AcceptRequest().

◆ Put() [2/2]

template<typename TRequest >
CBlockingQueue< TRequest >::TItemHandle CBlockingQueue< TRequest >::Put ( const TRequest &  request,
TUserPriority  priority = 0,
unsigned int  timeout_sec = 0,
unsigned int  timeout_nsec = 0 
)

Put a request into the queue.

If the queue remains full for the duration of the (optional) timeout, throw an exception.

Parameters
requestRequest
priorityThe priority of the request. The higher the priority the sooner the request will be processed.
timeout_secNumber of whole seconds in timeout
timeout_nsecNumber of additional nanoseconds in timeout

Definition at line 698 of file thread_pool_old.hpp.

References data, set< Key, Compare >::insert(), NCBI_THROW, NON_CONST_ITERATE, set< Key, Compare >::size(), val, and CBlockingQueue< TRequest >::x_PutSemPred().

◆ Register() [1/3]

bool CPoolOfThreads_ForServer::Register ( TThread thread)
private

Register a thread.

It is called by TThread::Main.

Parameters
threadA thread to register
returnWhether registration succeeded. (KillAllThreads disables it.)

Definition at line 315 of file server.cpp.

References CPoolOfThreads_ForServer::m_KilledAll, CPoolOfThreads_ForServer::m_Mutex, and CPoolOfThreads_ForServer::m_Threads.

Referenced by CThreadInPool_ForServer::Main().

◆ Register() [2/3]

template<typename TRequest >
virtual void CPoolOfThreads< TRequest >::Register ( TThread thread)
inlineprotectedvirtual

Register a thread.

It is called by TThread::Main. It should detach a thread if not tracking

Parameters
threadA thread to register

Definition at line 490 of file thread_pool_old.hpp.

Referenced by CThreadInPool< TRequest >::Main().

◆ Register() [3/3]

void CStdPoolOfThreads::Register ( TThread thread)
virtual

◆ RequestExclusiveExecution()

void CThreadPool::RequestExclusiveExecution ( CThreadPool_Task task,
TExclusiveFlags  flags = 0 
)

Add the task for exclusive execution in the pool By default the pool suspends all new and queued tasks processing, finishes execution of all currently executing tasks and then executes exclusive task in special thread devoted to this work.

The environment in which exclusive task executes can be modified by flags parameter. This method does not wait for exclusive execution, it is just adds the task to exclusive queue and starts the process of exclusive environment preparation. If next exclusive task will be added before preveous finishes (or even starts) its execution then they will be executed consequently each in its own exclusive environment (if flags parameter for them is different).

Parameters
taskTask to execute exclusively
flagsParameters of the exclusive environment

Definition at line 2249 of file thread_pool.cpp.

References flags, CThreadPool::m_Impl, and CThreadPool_Impl::RequestExclusiveExecution().

◆ RequestToCancel()

void CThreadPool_Task::RequestToCancel ( void  )

Cancel the task.

Equivalent to calling CThreadPool::CancelTask(task).

Note
If the task is executing it may not be canceled right away. It is responsibility of method Execute() implementation to check value of IsCancelRequested() periodically and finish its execution when this value is TRUE.
If the task has already finished its execution then do nothing.

Definition at line 1047 of file thread_pool.cpp.

References CThreadPool_Impl::CancelTask(), CThreadPool_Task::IsFinished(), CThreadPool_Task::m_Pool, and CThreadPool_Task::x_RequestToCancel().

Referenced by CPSG_PrefetchCDD_Task::Cancel(), CPSG_AnnotRecordsNA_Task::ProcessReplyItem(), CPSG_AnnotRecordsCDD_Task::ProcessReplyItem(), and CPSG_CDDAnnotBulk_Task::ProcessReplyItem().

◆ SetChangeCalcTime()

void CThreadPool_Controller_PID::SetChangeCalcTime ( double  calc_time)
inline

Set the time period (in seconds) for which average speed of changing of waiting tasks number is calculated.

Average speed is calculated by simple division of changing in waiting tasks number during this time period per time period value (all counts of tasks are calculated per each thread). By default parameter is set to 0.3.

Definition at line 211 of file thread_pool_ctrl.hpp.

References CThreadPool_Controller_PID::m_DerivTime.

◆ SetChangePredictTime()

void CThreadPool_Controller_PID::SetChangePredictTime ( double  predict_time)
inline

Set period of prediction of number of tasks in queue The meaning of parameter is only approximate.

In fact it is the coefficient in derivative part of the algorithm. Meaning of the coefficient is like this: take average speed of changing of tasks count, multiply it by this prediction time, if the resulting value is greater than threshold then new thread is needed. By default parameter is set to 0.5.

See also
SetQueuedTasksThreshold()

Definition at line 223 of file thread_pool_ctrl.hpp.

References CThreadPool_Controller_PID::m_DerivCoeff.

◆ SetDestroyTimeout()

void CThreadPool::SetDestroyTimeout ( const CTimeSpan timeout)

Set timeout to wait for all threads to finish before the pool should be able to destroy.

Default value is 10 seconds

Note
This method is meant to be called very rarely. Because of that it is implemented in non-threadsafe manner. While this method is working it is not allowed to call itself or GetDestroyTimeout() in other threads.

Definition at line 2237 of file thread_pool.cpp.

References CThreadPool::m_Impl, and CThreadPool_Impl::SetDestroyTimeout().

◆ SetMaxThreads()

void CThreadPool_Controller::SetMaxThreads ( unsigned int  max_threads)

◆ SetMinThreads()

void CThreadPool_Controller::SetMinThreads ( unsigned int  min_threads)

◆ SetQueuedTasksThreshold()

void CThreadPool_Controller_PID::SetQueuedTasksThreshold ( double  threshold)
inline

Set maximum number of tasks in queue per each thread The meaning of parameter is only approximate.

In fact it is the coefficient in proportional part of the algorithm and adjustment for all other coefficients. By default parameter is set to 3.

Definition at line 187 of file thread_pool_ctrl.hpp.

References CThreadPool_Controller_PID::m_Threshold.

◆ SetRequest()

template<typename TRequest >
TRequest& CBlockingQueue< TRequest >::CQueueItem::SetRequest ( void  )
inline

Definition at line 240 of file thread_pool_old.hpp.

◆ SetTaskMaxQueuedTime()

void CThreadPool_Controller_PID::SetTaskMaxQueuedTime ( double  queued_time)
inline

Set maximum time (in seconds) that task can wait in queue for processing until new thread will be launched.

The meaning of parameter is only approximate. In fact it is the coefficient in integral part of the algorithm and effectively if only one task will be considered then coefficient will be multiplied by number of currently running threads and currently set threshold. By default parameter is set to 0.2.

See also
SetQueuedTasksThreshold()

Definition at line 199 of file thread_pool_ctrl.hpp.

References CThreadPool_Controller_PID::m_IntegrCoeff.

◆ SetThreadsCount()

void CThreadPool_Controller::SetThreadsCount ( unsigned int  count)
protected

Set number of threads in pool Adjust given number to conform to minimum and maximum threads count constraints if needed.

Definition at line 2074 of file thread_pool.cpp.

References CThreadPool_Impl::FinishThreads(), CThreadPool_Controller::GetMaxThreads(), CThreadPool_Controller::GetMinThreads(), CThreadPool_Impl::GetThreadsCount(), CThreadPool_Impl::LaunchThreads(), and CThreadPool_Controller::m_Pool.

Referenced by CThreadPool_Controller_PID::OnEvent().

◆ SetUserPriority() [1/2]

template<typename TRequest >
void CBlockingQueue< TRequest >::SetUserPriority ( TItemHandle  handle,
TUserPriority  priority 
)

Adjust a pending request's priority.

Definition at line 833 of file thread_pool_old.hpp.

References set< Key, Compare >::end(), set< Key, Compare >::erase(), set< Key, Compare >::find(), and set< Key, Compare >::insert().

◆ SetUserPriority() [2/2]

template<typename TRequest >
void CPoolOfThreads< TRequest >::SetUserPriority ( TItemHandle  handle,
TUserPriority  priority 
)
inline

Adjust a pending request's priority.

Definition at line 1217 of file thread_pool_old.hpp.

◆ Spawn() [1/2]

void CPoolOfThreads_ForServer::Spawn ( unsigned int  num_threads)

Start processing threads.

Parameters
num_threadsThe number of threads to start

Definition at line 263 of file server.cpp.

References i, CPoolOfThreads_ForServer::NewThread(), and thr.

Referenced by CServer::x_DoRun().

◆ Spawn() [2/2]

template<typename TRequest >
void CPoolOfThreads< TRequest >::Spawn ( unsigned int  num_threads)

Start processing threads.

Parameters
num_threadsThe number of threads to start

Definition at line 1081 of file thread_pool_old.hpp.

References i.

Referenced by SGridWorkerNodeImpl::x_StartWorkerThreads().

◆ SThreadPool_PID_ErrInfo()

SThreadPool_PID_ErrInfo::SThreadPool_PID_ErrInfo ( double  time_,
double  err_ 
)
inline

Definition at line 64 of file thread_pool_ctrl.hpp.

◆ UnRegister() [1/3]

void CPoolOfThreads_ForServer::UnRegister ( TThread thread)
private

Unregister a thread.

Parameters
threadA thread to unregister

Definition at line 327 of file server.cpp.

References CPoolOfThreads_ForServer::m_KilledAll, CPoolOfThreads_ForServer::m_Mutex, and CPoolOfThreads_ForServer::m_Threads.

Referenced by CThreadInPool_ForServer::x_UnregisterThread().

◆ UnRegister() [2/3]

template<typename TRequest >
virtual void CPoolOfThreads< TRequest >::UnRegister ( TThread )
inlineprotectedvirtual

Unregister a thread.

Parameters
threadA thread to unregister

Definition at line 496 of file thread_pool_old.hpp.

Referenced by CThreadInPool< TRequest >::x_UnregisterThread().

◆ UnRegister() [3/3]

void CStdPoolOfThreads::UnRegister ( TThread thread)
virtual

Unregister a thread.

Parameters
threadA thread to unregister

Definition at line 113 of file thread_pool_old.cpp.

References CAtomicCounter::Get(), CPoolOfThreads< CRef< CStdRequest > >::m_MaxThreads, CPoolOfThreads< CRef< CStdRequest > >::m_Mutex, and CStdPoolOfThreads::m_Threads.

◆ WaitForHunger()

template<typename TRequest >
void CBlockingQueue< TRequest >::WaitForHunger ( unsigned int  timeout_sec = kMax_UInt,
unsigned int  timeout_nsec = 0 
) const

Wait for the queue to have waiting readers, for up to timeout_sec + timeout_nsec/1E9 seconds.

Parameters
timeout_secNumber of seconds
timeout_nsecNumber of nanoseconds

Definition at line 751 of file thread_pool_old.hpp.

References NCBI_THROW, and CBlockingQueue< TRequest >::x_HungerSemPred().

◆ WaitForRoom() [1/2]

template<typename TRequest >
void CPoolOfThreads< TRequest >::WaitForRoom ( unsigned int  timeout_sec = kMax_UInt,
unsigned int  timeout_nsec = 0 
)
inline

Wait for the room in the queue up to timeout_sec + timeout_nsec/1E9 seconds.

Parameters
timeout_secNumber of seconds
timeout_nsecNumber of nanoseconds

Definition at line 1143 of file thread_pool_old.hpp.

Referenced by CMainLoopThread::Main(), and SGridWorkerNodeImpl::OfflineRun().

◆ WaitForRoom() [2/2]

template<typename TRequest >
void CBlockingQueue< TRequest >::WaitForRoom ( unsigned int  timeout_sec = kMax_UInt,
unsigned int  timeout_nsec = 0 
) const

Wait for room in the queue for up to timeout_sec + timeout_nsec/1E9 seconds.

Parameters
timeout_secNumber of seconds
timeout_nsecNumber of nanoseconds

Definition at line 736 of file thread_pool_old.hpp.

References NCBI_THROW, and CBlockingQueue< TRequest >::x_PutSemPred().

◆ Withdraw() [1/2]

template<typename TRequest >
void CBlockingQueue< TRequest >::Withdraw ( TItemHandle  handle)

◆ Withdraw() [2/2]

template<typename TRequest >
void CPoolOfThreads< TRequest >::Withdraw ( TItemHandle  handle)
inline

Withdraw a pending request from consideration.

Definition at line 469 of file thread_pool_old.hpp.

◆ x_AcceptRequest()

template<typename TRequest >
CPoolOfThreads< TRequest >::TItemHandle CPoolOfThreads< TRequest >::x_AcceptRequest ( const TRequest &  req,
TUserPriority  priority,
bool  urgent,
unsigned int  timeout_sec = 0,
unsigned int  timeout_nsec = 0 
)
inlineprivate

Definition at line 1158 of file thread_pool_old.hpp.

References m_MaxThreads, and NCBI_THROW.

◆ x_AttachToPool()

void CThreadPool_Controller::x_AttachToPool ( CThreadPool_Impl pool)
inlineprivate

Attach the controller to ThreadPool.

Definition at line 923 of file thread_pool.cpp.

References CThreadPool_Controller::m_Pool, NCBI_THROW, and NULL.

Referenced by CThreadPool_Impl::x_Init().

◆ x_DetachFromPool()

void CThreadPool_Controller::x_DetachFromPool ( void  )
inlineprivate

Detach the controller from pool when pool is aborted.

Definition at line 934 of file thread_pool.cpp.

References CThreadPool_Controller::m_Pool, and NULL.

Referenced by CThreadPool_Impl::Abort().

◆ x_GetSemPred()

template<typename TRequest >
bool CBlockingQueue< TRequest >::x_GetSemPred ( const TRealQueue q) const
inlineprivate

Definition at line 280 of file thread_pool_old.hpp.

Referenced by CBlockingQueue< TRequest >::GetHandle().

◆ x_HandleOneRequest() [1/2]

void CThreadInPool_ForServer::x_HandleOneRequest ( bool  catch_all)
private

◆ x_HandleOneRequest() [2/2]

template<typename TRequest >
void CThreadInPool< TRequest >::x_HandleOneRequest ( bool  catch_all)
private

◆ x_HungerSemPred()

template<typename TRequest >
bool CBlockingQueue< TRequest >::x_HungerSemPred ( const TRealQueue q) const
inlineprivate

Definition at line 284 of file thread_pool_old.hpp.

Referenced by CBlockingQueue< TRequest >::WaitForHunger().

◆ x_Init()

void CThreadPool_Task::x_Init ( unsigned int  priority)
private

Init all members in constructor.

Parameters
priorityPriority of the task

Definition at line 952 of file thread_pool.cpp.

References CThreadPool_Task::eIdle, CThreadPool_Task::m_CancelRequested, CThreadPool_Task::m_Pool, CThreadPool_Task::m_Priority, CThreadPool_Task::m_Status, and NULL.

Referenced by CThreadPool_Task::CThreadPool_Task().

◆ x_OnExit()

template<typename TRequest >
virtual void CThreadInPool< TRequest >::x_OnExit ( void  )
inlineprotectedvirtual

Clean up. It is called by OnExit()

Definition at line 348 of file thread_pool_old.hpp.

Referenced by CThreadInPool< TRequest >::OnExit().

◆ x_PutSemPred()

template<typename TRequest >
bool CBlockingQueue< TRequest >::x_PutSemPred ( const TRealQueue q) const
inlineprivate

◆ x_RequestToCancel()

void CThreadPool_Task::x_RequestToCancel ( void  )
inlineprivate

◆ x_ResetOwner()

void CThreadPool_Task::x_ResetOwner ( void  )
inlineprivate

Detach task from the pool (if insertion into the pool has failed).

Definition at line 1007 of file thread_pool.cpp.

References CAtomicCounter::Add(), CThreadPool_Task::m_IsBusy, CThreadPool_Task::m_Pool, and NULL.

Referenced by CThreadPool_Impl::AddTask().

◆ x_RunNewThread()

template<typename TRequest >
void CPoolOfThreads< TRequest >::x_RunNewThread ( ERunMode  mode,
CAtomicCounter counter 
)
inlineprivate

Definition at line 1200 of file thread_pool_old.hpp.

References Critical(), ERR_POST_XX, and thr.

◆ x_SetOwner()

void CThreadPool_Task::x_SetOwner ( CThreadPool_Impl pool)
inlineprivate

◆ x_SetStatus() [1/5]

virtual void CQueueItemBase_ForServer::x_SetStatus ( EStatus  new_status)
inlineprotectedvirtual

◆ x_SetStatus() [2/5]

void CBlockingQueue_ForServer::CQueueItem::x_SetStatus ( EStatus  new_status)
inlineprotected

◆ x_SetStatus() [3/5]

void CThreadPool_Task::x_SetStatus ( EStatus  new_status)
private

◆ x_SetStatus() [4/5]

virtual void CQueueItemBase::x_SetStatus ( EStatus  new_status)
inlineprotectedvirtual

◆ x_SetStatus() [5/5]

template<typename TRequest >
void CBlockingQueue< TRequest >::CQueueItem::x_SetStatus ( EStatus  new_status)
inlineprotected

Definition at line 246 of file thread_pool_old.hpp.

◆ x_UnregisterThread() [1/2]

void CThreadInPool_ForServer::x_UnregisterThread ( void  )
private

◆ x_UnregisterThread() [2/2]

template<typename TRequest >
void CThreadInPool< TRequest >::x_UnregisterThread ( void  )
private

◆ x_WaitForPredicate()

template<typename TRequest >
bool CBlockingQueue< TRequest >::x_WaitForPredicate ( TQueuePredicate  pred,
CSemaphore sem,
CMutexGuard guard,
unsigned int  timeout_sec,
unsigned int  timeout_nsec 
) const
private

◆ ~CAutoUnregGuard() [1/2]

CThreadInPool_ForServer::CAutoUnregGuard::~CAutoUnregGuard ( void  )

Definition at line 158 of file server.cpp.

◆ ~CAutoUnregGuard() [2/2]

template<typename TRequest >
CThreadInPool< TRequest >::CAutoUnregGuard::~CAutoUnregGuard ( void  )

Definition at line 947 of file thread_pool_old.hpp.

◆ ~CCompletingHandle() [1/2]

CBlockingQueue_ForServer::CCompletingHandle::~CCompletingHandle ( )
inline

◆ ~CCompletingHandle() [2/2]

template<typename TRequest >
CBlockingQueue< TRequest >::CCompletingHandle::~CCompletingHandle ( )
inline

Definition at line 131 of file thread_pool_old.hpp.

◆ ~CPoolOfThreads()

template<typename TRequest >
CPoolOfThreads< TRequest >::~CPoolOfThreads ( void  )
virtual

Destructor.

Definition at line 1070 of file thread_pool_old.hpp.

References ERR_POST_XX, n, and Warning().

◆ ~CPoolOfThreads_ForServer()

CPoolOfThreads_ForServer::~CPoolOfThreads_ForServer ( void  )
virtual

◆ ~CStdPoolOfThreads()

CStdPoolOfThreads::~CStdPoolOfThreads ( )
virtual

Definition at line 126 of file thread_pool_old.cpp.

References CStdPoolOfThreads::KillAllThreads().

◆ ~CStdRequest()

virtual CStdRequest::~CStdRequest ( void  )
inlinevirtual

Destructor.

Definition at line 545 of file thread_pool_old.hpp.

◆ ~CThreadInPool()

template<typename TRequest >
CThreadInPool< TRequest >::~CThreadInPool ( void  )
protectedvirtual

Destructor.

Definition at line 934 of file thread_pool_old.hpp.

References NULL.

◆ ~CThreadInPool_ForServer()

CThreadInPool_ForServer::~CThreadInPool_ForServer ( void  )
protectedvirtual

◆ ~CThreadPool()

CThreadPool::~CThreadPool ( void  )
virtual

Destructor – will wait for all its threads to finish with the timeout set by CThreadPool::SetDestroyTimeout(); current default is 10 seconds.

If this timeout is not enough for threads to terminate CThreadPool will be destroyed but all threads will finish later without any "segmentation fault" errors because CThreadPool_Impl object will remain in memory until all its threads finish.

Note
If this CThreadPool object is destroyed at the end of the application and it will fail to finish all threads in destructor, then all memory allocated by CThreadPool_Impl can be shown as leakage in the memory checking tools (like Valgrind). To avoid these leakages or for some other reasons to make sure that ThreadPool finishes all its operations before the destructor you can call method Abort() at any place in your application.
See also
Abort(), SetDestroyTimeout()

Definition at line 2195 of file thread_pool.cpp.

References CThreadPool_Impl::DestroyReference(), and CThreadPool::m_Impl.

◆ ~CThreadPool_Controller()

CThreadPool_Controller::~CThreadPool_Controller ( void  )
protectedvirtual

Destructor. Have to be called only from CRef.

Definition at line 2009 of file thread_pool.cpp.

◆ ~CThreadPool_Task()

CThreadPool_Task::~CThreadPool_Task ( void  )
protectedvirtual

Destructor. Will be called from CRef.

Definition at line 962 of file thread_pool.cpp.

◆ ~CThreadPool_Thread()

CThreadPool_Thread::~CThreadPool_Thread ( void  )
protectedvirtual

Destructor.

Definition at line 2137 of file thread_pool.cpp.

References CThreadPool_Thread::m_Impl.

Variable Documentation

◆ call_time

double SThreadPool_PID_ErrInfo::call_time

Time of history entry.

Definition at line 60 of file thread_pool_ctrl.hpp.

◆ err

double SThreadPool_PID_ErrInfo::err

Value of the error.

Definition at line 62 of file thread_pool_ctrl.hpp.

◆ m_CancelRequested

atomic<bool> CThreadPool_Task::m_CancelRequested
private

Flag indicating if cancellation of the task was already requested.

Definition at line 196 of file thread_pool.hpp.

Referenced by CThreadPool_Task::IsCancelRequested(), CThreadPool_Task::x_Init(), and CThreadPool_Task::x_RequestToCancel().

◆ m_Counted

bool CThreadInPool_ForServer::m_Counted
private

◆ m_Counter

template<typename TRequest >
CAtomicCounter* CThreadInPool< TRequest >::m_Counter
private

Definition at line 377 of file thread_pool_old.hpp.

Referenced by CThreadInPool< TRequest >::x_UnregisterThread().

◆ m_Delta

template<typename TRequest >
atomic<int> CPoolOfThreads< TRequest >::m_Delta
protected

The difference between the number of unfinished requests and the total number of threads in the pool.

Definition at line 512 of file thread_pool_old.hpp.

Referenced by CThreadInPool< TRequest >::x_HandleOneRequest().

◆ m_DerivCoeff

double CThreadPool_Controller_PID::m_DerivCoeff
private

◆ m_DerivTime

double CThreadPool_Controller_PID::m_DerivTime
private

◆ m_ErrHistory

deque<SThreadPool_PID_ErrInfo> CThreadPool_Controller_PID::m_ErrHistory
private

History of changing of "error" value "error" - number of tasks per thread waiting in queue.

Controller will try to tend this value to zero.

Definition at line 164 of file thread_pool_ctrl.hpp.

Referenced by CThreadPool_Controller_PID::CThreadPool_Controller_PID(), CThreadPool_Controller_PID::GetSafeSleepTime(), and CThreadPool_Controller_PID::OnEvent().

◆ m_GetCond

CConditionVariable CBlockingQueue_ForServer::m_GetCond
protected

◆ m_GetSem

template<typename TRequest >
CSemaphore CBlockingQueue< TRequest >::m_GetSem
protected

Raised if the queue contains data.

Definition at line 268 of file thread_pool_old.hpp.

◆ m_HungerCnt

template<typename TRequest >
size_t CBlockingQueue< TRequest >::m_HungerCnt
protected

Number of threads waiting for data.

Definition at line 272 of file thread_pool_old.hpp.

Referenced by CBlockingQueue< CRef< CStdRequest > >::GetHunger(), and CBlockingQueue< CRef< CStdRequest > >::x_HungerSemPred().

◆ m_HungerSem

template<typename TRequest >
CSemaphore CBlockingQueue< TRequest >::m_HungerSem
mutableprotected

Raised if Get[Handle] has to wait.

Definition at line 270 of file thread_pool_old.hpp.

◆ m_Impl [1/2]

CThreadPool_Impl* CThreadPool::m_Impl
private

◆ m_Impl [2/2]

CThreadPool_ThreadImpl* CThreadPool_Thread::m_Impl
private

◆ m_InHandleEvent

bool CThreadPool_Controller::m_InHandleEvent
private

If controller is already inside HandleEvent() processing.

Definition at line 595 of file thread_pool.hpp.

Referenced by CThreadPool_Controller::HandleEvent().

◆ m_IntegrCoeff

double CThreadPool_Controller_PID::m_IntegrCoeff
private

◆ m_IntegrErr

double CThreadPool_Controller_PID::m_IntegrErr
private

Value of "error" integrated over all working time.

Definition at line 166 of file thread_pool_ctrl.hpp.

Referenced by CThreadPool_Controller_PID::GetSafeSleepTime(), and CThreadPool_Controller_PID::OnEvent().

◆ m_IsBusy

CAtomicCounter_WithAutoInit CThreadPool_Task::m_IsBusy
private

Flag indicating that the task is already added to some pool.

Definition at line 188 of file thread_pool.hpp.

Referenced by CThreadPool_Task::operator=(), CThreadPool_Task::x_ResetOwner(), and CThreadPool_Task::x_SetOwner().

◆ m_KilledAll

bool CPoolOfThreads_ForServer::m_KilledAll
private

◆ m_MaxSize

template<typename TRequest >
size_t CBlockingQueue< TRequest >::m_MaxSize
private

The maximum size of the queue.

Definition at line 275 of file thread_pool_old.hpp.

Referenced by CBlockingQueue< CRef< CStdRequest > >::GetMaxSize(), and CBlockingQueue< CRef< CStdRequest > >::x_PutSemPred().

◆ m_MaxThreads [1/3]

volatile TACValue CPoolOfThreads_ForServer::m_MaxThreads
private

The maximum number of threads the pool can hold.

Definition at line 275 of file thread_pool_for_server.hpp.

Referenced by CPoolOfThreads_ForServer::KillAllThreads().

◆ m_MaxThreads [2/3]

unsigned int CThreadPool_Controller::m_MaxThreads
private

Maximum number of threads in pool.

Definition at line 593 of file thread_pool.hpp.

Referenced by CThreadPool_Controller::EnsureLimits(), CThreadPool_Controller::GetMaxThreads(), and CThreadPool_Controller::SetMaxThreads().

◆ m_MaxThreads [3/3]

template<typename TRequest >
CAtomicCounter_WithAutoInit CPoolOfThreads< TRequest >::m_MaxThreads
protected

The maximum number of threads the pool can hold.

Definition at line 502 of file thread_pool_old.hpp.

◆ m_MaxUrgentThreads

template<typename TRequest >
CAtomicCounter_WithAutoInit CPoolOfThreads< TRequest >::m_MaxUrgentThreads
protected

The maximum number of urgent threads running simultaneously.

Definition at line 504 of file thread_pool_old.hpp.

◆ m_MinThreads

unsigned int CThreadPool_Controller::m_MinThreads
private

Minimum number of threads in pool.

Definition at line 591 of file thread_pool.hpp.

Referenced by CThreadPool_Controller::EnsureLimits(), CThreadPool_Controller::GetMinThreads(), and CThreadPool_Controller::SetMinThreads().

◆ m_Mutex [1/4]

CMutex CBlockingQueue_ForServer::m_Mutex
mutableprotected

Guards access to queue.

Definition at line 141 of file thread_pool_for_server.hpp.

Referenced by CBlockingQueue_ForServer::GetHandle(), and CBlockingQueue_ForServer::Put().

◆ m_Mutex [2/4]

CMutex CPoolOfThreads_ForServer::m_Mutex
private

The guard for m_MaxThreads and m_MaxUrgentThreads.

Definition at line 279 of file thread_pool_for_server.hpp.

Referenced by CPoolOfThreads_ForServer::Register(), and CPoolOfThreads_ForServer::UnRegister().

◆ m_Mutex [3/4]

template<typename TRequest >
CMutex CBlockingQueue< TRequest >::m_Mutex
mutableprotected

Guards access to queue.

Definition at line 271 of file thread_pool_old.hpp.

◆ m_Mutex [4/4]

template<typename TRequest >
CMutex CPoolOfThreads< TRequest >::m_Mutex
mutableprotected

The guard for m_MaxThreads, m_MaxUrgentThreads, and m_Delta.

Definition at line 514 of file thread_pool_old.hpp.

Referenced by CThreadInPool< TRequest >::x_HandleOneRequest().

◆ m_Pool [1/4]

TPool* CThreadInPool_ForServer::m_Pool
private

◆ m_Pool [2/4]

atomic<CThreadPool_Impl*> CThreadPool_Task::m_Pool
private

◆ m_Pool [3/4]

atomic<CThreadPool_Impl*> CThreadPool_Controller::m_Pool
private

◆ m_Pool [4/4]

template<typename TRequest >
TPool* CThreadInPool< TRequest >::m_Pool
private

◆ m_Priority [1/2]

unsigned int CThreadPool_Task::m_Priority
private

◆ m_Priority [2/2]

TPriority CQueueItemBase::m_Priority
protected

◆ m_PutSem

template<typename TRequest >
CSemaphore CBlockingQueue< TRequest >::m_PutSem
mutableprotected

Raised if the queue has room.

Definition at line 269 of file thread_pool_old.hpp.

◆ m_Queue [1/4]

TRealQueue CBlockingQueue_ForServer::m_Queue
protected

◆ m_Queue [2/4]

TQueue CPoolOfThreads_ForServer::m_Queue
private

◆ m_Queue [3/4]

template<typename TRequest >
volatile TRealQueue CBlockingQueue< TRequest >::m_Queue
protected

The queue.

Definition at line 267 of file thread_pool_old.hpp.

◆ m_Queue [4/4]

template<typename TRequest >
TQueue CPoolOfThreads< TRequest >::m_Queue
protected

◆ m_QueuingForbidden

template<typename TRequest >
bool CPoolOfThreads< TRequest >::m_QueuingForbidden
protected

Definition at line 517 of file thread_pool_old.hpp.

◆ m_Request [1/2]

TRequest CBlockingQueue_ForServer::CQueueItem::m_Request
private

◆ m_Request [2/2]

template<typename TRequest >
TRequest CBlockingQueue< TRequest >::CQueueItem::m_Request
private

◆ m_RequestCounter

template<typename TRequest >
Uint4 CBlockingQueue< TRequest >::m_RequestCounter
private

Definition at line 276 of file thread_pool_old.hpp.

◆ m_RunMode

template<typename TRequest >
ERunMode CThreadInPool< TRequest >::m_RunMode
private

How long to keep running.

Definition at line 376 of file thread_pool_old.hpp.

Referenced by CThreadInPool< CRef< CStdRequest > >::GetRunMode(), and CThreadInPool< TRequest >::Main().

◆ m_Status [1/3]

EStatus CQueueItemBase_ForServer::m_Status
protected

◆ m_Status [2/3]

atomic<EStatus> CThreadPool_Task::m_Status
private

◆ m_Status [3/3]

EStatus CQueueItemBase::m_Status
protected

Definition at line 100 of file thread_pool_old.hpp.

Referenced by CQueueItemBase::GetStatus(), and CQueueItemBase::x_SetStatus().

◆ m_Thread [1/2]

TThread* CThreadInPool_ForServer::CAutoUnregGuard::m_Thread
private

Definition at line 201 of file thread_pool_for_server.hpp.

◆ m_Thread [2/2]

template<typename TRequest >
TThread* CThreadInPool< TRequest >::CAutoUnregGuard::m_Thread
private

Definition at line 369 of file thread_pool_old.hpp.

◆ m_ThreadCount [1/2]

CAtomicCounter CPoolOfThreads_ForServer::m_ThreadCount
private

◆ m_ThreadCount [2/2]

template<typename TRequest >
CAtomicCounter_WithAutoInit CPoolOfThreads< TRequest >::m_ThreadCount
protected

The current number of threads in the pool.

Definition at line 507 of file thread_pool_old.hpp.

◆ m_ThreadName

template<typename TRequest >
const string CPoolOfThreads< TRequest >::m_ThreadName
protected

Definition at line 519 of file thread_pool_old.hpp.

Referenced by CThreadInPool< TRequest >::Main().

◆ m_Threads [1/2]

TThreads CPoolOfThreads_ForServer::m_Threads
private

◆ m_Threads [2/2]

TThreads CStdPoolOfThreads::m_Threads
private

◆ m_Threshold [1/2]

double CThreadPool_Controller_PID::m_Threshold
private

◆ m_Threshold [2/2]

template<typename TRequest >
int CPoolOfThreads< TRequest >::m_Threshold
protected

for delta

Definition at line 505 of file thread_pool_old.hpp.

◆ m_ThrSuffix

string CPoolOfThreads_ForServer::m_ThrSuffix
private

Definition at line 282 of file thread_pool_for_server.hpp.

Referenced by CThreadInPool_ForServer::Main().

◆ m_Timer

CStopWatch CThreadPool_Controller_PID::m_Timer
private

Timer for measuring time periods.

Definition at line 160 of file thread_pool_ctrl.hpp.

Referenced by CThreadPool_Controller_PID::OnEvent().

◆ m_UrgentThreadCount

template<typename TRequest >
CAtomicCounter_WithAutoInit CPoolOfThreads< TRequest >::m_UrgentThreadCount
protected

The current number of urgent threads running now.

Definition at line 509 of file thread_pool_old.hpp.

Friends

◆ CAutoUnregGuard [1/2]

friend class CAutoUnregGuard
friend

Definition at line 204 of file thread_pool_for_server.hpp.

◆ CAutoUnregGuard [2/2]

template<typename TRequest >
friend class CAutoUnregGuard
friend

Definition at line 372 of file thread_pool_old.hpp.

◆ CBlockingQueue< TRequest >

template<typename TRequest >
friend class CBlockingQueue< TRequest >
friend

Definition at line 246 of file thread_pool_old.hpp.

◆ CBlockingQueue_ForServer

friend class CBlockingQueue_ForServer
friend

Definition at line 128 of file thread_pool_for_server.hpp.

◆ CThreadInPool< TRequest >

template<typename TRequest >
friend class CThreadInPool< TRequest >
friend

Definition at line 519 of file thread_pool_old.hpp.

◆ CThreadInPool_ForServer

friend class CThreadInPool_ForServer
friend

Definition at line 251 of file thread_pool_for_server.hpp.

Referenced by CPoolOfThreads_ForServer::NewThread().

◆ CThreadPool_Impl [1/3]

friend class CThreadPool_Impl
friend

Definition at line 168 of file thread_pool.hpp.

◆ CThreadPool_Impl [2/3]

friend class CThreadPool_Impl
friend

Definition at line 413 of file thread_pool.hpp.

Referenced by CThreadPool::CThreadPool().

◆ CThreadPool_Impl [3/3]

friend class CThreadPool_Impl
friend

Definition at line 576 of file thread_pool.hpp.

◆ CThreadPool_ThreadImpl

friend class CThreadPool_ThreadImpl
friend

Definition at line 454 of file thread_pool.hpp.

Referenced by CThreadPool_Thread::CThreadPool_Thread().

Modified on Sat May 25 14:16:39 2024 by modify_doxy.py rev. 669887