Search Toolkit Book for CThreadPool_Impl
Real implementation of all ThreadPool functions. More...
CThreadPool_Impl (CThreadPool *pool_intf, unsigned int queue_size, unsigned int max_threads, unsigned int min_threads, CThread::TRunMode threads_mode=CThread::fRunDefault) Constructor with default controller. More...Real implementation of all ThreadPool functions.
Definition at line 58 of file thread_pool.cpp.
◆ TExclusiveFlags ◆ TExclusiveQueueType of queue used for storing information about exclusive tasks.
Definition at line 258 of file thread_pool.cpp.
◆ TQueue ◆ TThreadsList ◆ TWaitPredicate typedef bool(CThreadPool_Impl::* CThreadPool_Impl::TWaitPredicate) (void) const private ◆ CThreadPool_Impl() [1/3] ◆ CThreadPool_Impl() [2/3] ◆ CThreadPool_Impl() [3/3]Prohibit copying and assigning.
◆ ~CThreadPool_Impl() CThreadPool_Impl::~CThreadPool_Impl ( void ) private ◆ Abort()Abort the pool operation.
Definition at line 1916 of file thread_pool.cpp.
References CTimeSpan::AsSmartString(), CSyncQueue_AccessGuard< Type, Container, Traits >::Begin(), CSyncQueue< Type, Container, Traits >::Clear(), Critical(), CSyncQueue_AccessGuard< Type, Container, Traits >::End(), ERR_POST_X, CStopWatch::eStart, FinishThreads(), GetQueuedTasksCount(), CSyncQueue< Type, Container, Traits >::GetSize(), GetThreadsCount(), m_Aborted, m_AbortWait, m_Controller, m_ExclusiveQueue, m_ServiceThread, CRef< C, Locker >::NotNull(), CSemaphore::Post(), CThreadPool_ServiceThread::RequestToFinish(), Warning(), x_CancelExecutingTasks(), x_CancelQueuedTasks(), CThreadPool_Controller::x_DetachFromPool(), x_HasNoThreads(), and x_WaitForPredicate().
Referenced by CThreadPool::Abort(), and DestroyReference().
◆ AddTask()Add task to the pool.
Definition at line 1669 of file thread_pool.cpp.
References _ASSERT, CAtomicCounter::Add(), CallControllerOther(), check_flags(), count, CThreadPool_Task::eIdle, CStopWatch::Elapsed(), CThreadPool_Task::eQueued, CStopWatch::eStart, CThreadPool::fCancelQueuedTasks, CThreadPool::fDoNotAllowNewTasks, CTimeSpan::GetAsDouble(), GetQueuedTasksCount(), CSyncQueue< Type, Container, Traits >::GetSize(), GetThreadsCount(), CThreadPool_Guard::Guard(), int, IsSuspended(), ITERATE, LaunchThreads(), m_Aborted, m_IdleThreads, m_IsQueueAllowed, m_Queue, m_RoomWait, m_SuspendFlags, m_TotalTasks, NCBI_THROW, CSyncQueue< Type, Container, Traits >::Push(), Ref(), ThrowAddProhibited(), x_CanAddImmediateTask(), x_CancelQueuedTasks(), x_NoNewTaskAllowed(), CThreadPool_Task::x_ResetOwner(), CThreadPool_Task::x_SetOwner(), CThreadPool_Task::x_SetStatus(), and x_WaitForPredicate().
Referenced by CThreadPool::AddTask().
◆ CallController() ◆ CallControllerOther() void CThreadPool_Impl::CallControllerOther ( void ) inline ◆ CancelTask()Request to cancel the task.
Definition at line 1799 of file thread_pool.cpp.
References _ASSERT, CallControllerOther(), CThreadPool_Task::eIdle, CThreadPool_Task::GetPool(), CThreadPool_Task::GetStatus(), CThreadPool_Task::IsFinished(), m_Interface, NCBI_THROW, x_RemoveTaskFromQueue(), and CThreadPool_Task::x_RequestToCancel().
Referenced by CThreadPool::CancelTask(), and CThreadPool_Task::RequestToCancel().
◆ CancelTasks() ◆ CanDoExclusiveTask() bool CThreadPool_Impl::CanDoExclusiveTask ( void ) const inline ◆ DestroyReference() void CThreadPool_Impl::DestroyReference ( void ) inline ◆ FinishThreads() void CThreadPool_Impl::FinishThreads ( unsigned int count ) ◆ FlushThreads()Finish all current threads and replace them with new ones.
Definition at line 1880 of file thread_pool.cpp.
References CThreadPool::eStartImmediately, CThreadPool::eWaitToFinish, CThreadPool::fFlushThreads, FinishThreads(), CSyncQueue< Type, Container, Traits >::GetSize(), GetThreadsCount(), IsSuspended(), m_Aborted, m_ExclusiveQueue, m_FlushRequested, NCBI_THROW, and RequestExclusiveExecution().
Referenced by CThreadPool::FlushThreads().
◆ GetDestroyTimeout() ◆ GetExecutingTasksCount() unsigned int CThreadPool_Impl::GetExecutingTasksCount ( void ) const inline ◆ GetMainPoolMutex() CMutex & CThreadPool_Impl::GetMainPoolMutex ( void ) inline ◆ GetPoolInterface() CThreadPool * CThreadPool_Impl::GetPoolInterface ( void ) const inline ◆ GetQueuedTasksCount() unsigned int CThreadPool_Impl::GetQueuedTasksCount ( void ) const inline ◆ GetSafeSleepTime() CTimeSpan CThreadPool_Impl::GetSafeSleepTime ( void ) const inline ◆ GetThreadsCount() unsigned int CThreadPool_Impl::GetThreadsCount ( void ) const inline ◆ IsAborted() bool CThreadPool_Impl::IsAborted ( void ) const inline ◆ IsSuspended() bool CThreadPool_Impl::IsSuspended ( void ) const inline ◆ LaunchThreads() void CThreadPool_Impl::LaunchThreads ( unsigned int count )Launch new threads in pool.
Definition at line 1499 of file thread_pool.cpp.
References CAtomicCounter::Add(), CallControllerOther(), count, CThreadPool::CreateThread(), i, set< Key, Compare >::insert(), m_IdleThreads, m_Interface, m_ThreadsCount, m_ThreadsMode, and CThreadPool_ThreadImpl::s_GetImplPointer().
Referenced by AddTask(), CThreadPool_Controller::EnsureLimits(), and CThreadPool_Controller::SetThreadsCount().
◆ operator=() ◆ RequestExclusiveExecution()Add the task for exclusive execution in the pool.
Definition at line 1774 of file thread_pool.cpp.
References _ASSERT, CThreadPool_Task::eQueued, flags, m_Aborted, m_ExclusiveQueue, m_ServiceThread, NCBI_THROW, CSyncQueue< Type, Container, Traits >::Push(), Ref(), CThreadPool_ServiceThread::WakeUp(), CThreadPool_Task::x_SetOwner(), and CThreadPool_Task::x_SetStatus().
Referenced by FlushThreads(), and CThreadPool::RequestExclusiveExecution().
◆ RequestSuspend()Request suspension of the pool.
Definition at line 890 of file thread_pool.cpp.
References CallController(), CThreadPool_Controller::eSuspend, CThreadPool::fCancelExecutingTasks, CThreadPool::fCancelQueuedTasks, CThreadPool::fFlushThreads, FinishThreads(), flags, m_IdleThreads, m_Suspended, m_SuspendFlags, set< Key, Compare >::size(), x_CancelExecutingTasks(), and x_CancelQueuedTasks().
Referenced by CThreadPool_ServiceThread::Main().
◆ ResumeWork() void CThreadPool_Impl::ResumeWork ( void ) inline ◆ s_GetImplPointer() ◆ SetDestroyTimeout() void CThreadPool_Impl::SetDestroyTimeout ( const CTimeSpan & timeout ) inline ◆ SetInterfaceStarted() void CThreadPool_Impl::SetInterfaceStarted ( void ) inline ◆ SetThreadIdle()Mark thread as idle or non-idle.
Definition at line 1555 of file thread_pool.cpp.
References set< Key, Compare >::end(), set< Key, Compare >::erase(), CThreadPool::fFlushThreads, set< Key, Compare >::find(), CSyncQueue< Type, Container, Traits >::GetSize(), set< Key, Compare >::insert(), IsSuspended(), m_IdleThreads, m_Queue, m_SuspendFlags, m_WorkingThreads, CThreadPool_ThreadImpl::RequestToFinish(), ThreadStateChanged(), and CThreadPool_ThreadImpl::WakeUp().
Referenced by CThreadPool_ThreadImpl::x_SetIdleState().
◆ sx_RequestToCancel() ◆ sx_SetTaskStatus() ◆ TaskFinished() void CThreadPool_Impl::TaskFinished ( void ) inline ◆ TaskStarting() void CThreadPool_Impl::TaskStarting ( void ) inline ◆ ThreadStateChanged() void CThreadPool_Impl::ThreadStateChanged ( void ) inlineCallback when some thread changed its idleness or finished (including service thread)
Definition at line 798 of file thread_pool.cpp.
References CThreadPool::fFlushThreads, GetThreadsCount(), IsSuspended(), m_Aborted, m_AbortWait, m_ServiceThread, m_SuspendFlags, m_WorkingThreads, CSemaphore::Post(), set< Key, Compare >::size(), CThreadPool_ServiceThread::WakeUp(), and x_HasNoThreads().
Referenced by CThreadPool_ServiceThread::Main(), SetThreadIdle(), and ThreadStopped().
◆ ThreadStopped() ◆ TryGetExclusiveTask()Get the next exclusive task to execute.
Definition at line 857 of file thread_pool.cpp.
References CSyncQueue_AccessGuard< Type, Container, Traits >::Begin(), CThreadPool::fExecuteQueuedTasks, CThreadPool::fFlushThreads, CAtomicCounter::Get(), CSyncQueue< Type, Container, Traits >::GetSize(), info, m_ExclusiveQueue, m_FlushRequested, m_TotalTasks, and CSyncQueue< Type, Container, Traits >::Pop().
Referenced by CThreadPool_ServiceThread::Main().
◆ TryGetNextTask() ◆ x_CanAddImmediateTask() bool CThreadPool_Impl::x_CanAddImmediateTask ( void ) const private ◆ x_CancelExecutingTasks() void CThreadPool_Impl::x_CancelExecutingTasks ( void ) private ◆ x_CancelQueuedTasks() void CThreadPool_Impl::x_CancelQueuedTasks ( void ) privateCancel all tasks waiting in the queue.
Definition at line 1866 of file thread_pool.cpp.
References CSyncQueue_AccessGuard< Type, Container, Traits >::Begin(), CSyncQueue< Type, Container, Traits >::Clear(), CSyncQueue_AccessGuard< Type, Container, Traits >::End(), and m_Queue.
Referenced by Abort(), AddTask(), CancelTasks(), and RequestSuspend().
◆ x_GetQueueSize() unsigned int CThreadPool_Impl::x_GetQueueSize ( unsigned int queue_size ) inlineprivateTransform size of queue given in constructor to the size passed to CSyncQueue constructor.
Method can be called only from constructor because it initializes value of m_IsQueueAllowed member variable.
Definition at line 1403 of file thread_pool.cpp.
References m_IsQueueAllowed.
◆ x_HasNoThreads() bool CThreadPool_Impl::x_HasNoThreads ( void ) const private ◆ x_Init()Initialization of all class member variables that can be initialized outside of constructor.
Definition at line 1446 of file thread_pool.cpp.
References CThread::fRunAllowST, CThread::fRunDetached, m_Aborted, m_Controller, m_DestroyTimeout, m_ExecutingTasks, m_FlushRequested, m_Interface, m_SelfRef, m_ServiceThread, m_Suspended, m_ThreadsCount, m_ThreadsMode, m_TotalTasks, CAtomicCounter::Set(), and CThreadPool_Controller::x_AttachToPool().
Referenced by CThreadPool_Impl().
◆ x_NoNewTaskAllowed() bool CThreadPool_Impl::x_NoNewTaskAllowed ( void ) const inlineprivate ◆ x_RemoveTaskFromQueue() ◆ x_WaitForPredicate() ◆ m_Aborted atomic<bool> CThreadPool_Impl::m_Aborted private ◆ m_AbortWait ◆ m_Controller ◆ m_DestroyTimeout ◆ m_ExclusiveQueue ◆ m_ExecutingTasks ◆ m_FlushRequested volatile bool CThreadPool_Impl::m_FlushRequested private ◆ m_IdleThreads ◆ m_Interface ◆ m_IsQueueAllowed bool CThreadPool_Impl::m_IsQueueAllowed private ◆ m_MainPoolMutex CMutex CThreadPool_Impl::m_MainPoolMutex private ◆ m_Queue TQueue CThreadPool_Impl::m_Queue private ◆ m_RoomWait ◆ m_SelfRef ◆ m_ServiceThread ◆ m_Suspended atomic<bool> CThreadPool_Impl::m_Suspended privateIf pool is suspended for exclusive task execution or not.
Thread Checker can complain that access to this variable everywhere is not guarded by some mutex. But it's okay because special care is taken to make any race a matter of timing - suspend will happen properly in any case. Also everything is written with the assumption that there's no other threads (besides this very thread pool) that could call any methods here.
Definition at line 382 of file thread_pool.cpp.
Referenced by IsSuspended(), RequestSuspend(), ResumeWork(), and x_Init().
◆ m_SuspendFlags ◆ m_ThreadsCount ◆ m_ThreadsMode ◆ m_TotalTasks ◆ m_WorkingThreadsThe documentation for this class was generated from the following file:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4