NCBI C++ ToolKit
|
Search Toolkit Book for CThreadPool_ServiceThread
Thread used in pool for different internal needs: execution of exclusive tasks and passing events to controller. More...
Public Member Functions | |
CThreadPool_ServiceThread (CThreadPool_Impl *pool) | |
Constructor. More... | |
void | WakeUp (void) |
Wake up from idle waiting or waiting of pool preparing exclusive environment. More... | |
void | RequestToFinish (void) |
Request finishing of the thread. More... | |
bool | IsFinished (void) |
Check if this thread have already finished or not. More... | |
void | NeedCallController (void) |
Tell the thread that controller should handle eOther event. More... | |
Public Member Functions inherited from CThread | |
CThread (void) | |
Constructor. More... | |
bool | Run (TRunMode flags=fRunDefault) |
Run the thread. More... | |
void | Detach (void) |
Inform the thread that user does not need to wait for its termination. More... | |
void | Join (void **exit_data=0) |
Wait for the thread termination. More... | |
bool | Discard (void) |
If the thread has not been Run() yet, then schedule the thread object for destruction, and return TRUE. More... | |
bool | IsTerminated (void) const |
Check if the thread has been terminated. More... | |
Public Member Functions inherited from CObject | |
CObject (void) | |
Constructor. More... | |
CObject (const CObject &src) | |
Copy constructor. More... | |
virtual | ~CObject (void) |
Destructor. More... | |
CObject & | operator= (const CObject &src) THROWS_NONE |
Assignment operator. More... | |
bool | CanBeDeleted (void) const THROWS_NONE |
Check if object can be deleted. More... | |
bool | IsAllocatedInPool (void) const THROWS_NONE |
Check if object is allocated in memory pool (not system heap) More... | |
bool | Referenced (void) const THROWS_NONE |
Check if object is referenced. More... | |
bool | ReferencedOnlyOnce (void) const THROWS_NONE |
Check if object is referenced only once. More... | |
void | AddReference (void) const |
Add reference to object. More... | |
void | RemoveReference (void) const |
Remove reference to object. More... | |
void | ReleaseReference (void) const |
Remove reference without deleting object. More... | |
virtual void | DoNotDeleteThisObject (void) |
Mark this object as not allocated in heap – do not delete this object. More... | |
virtual void | DoDeleteThisObject (void) |
Mark this object as allocated in heap – object can be deleted. More... | |
void * | operator new (size_t size) |
Define new operator for memory allocation. More... | |
void * | operator new[] (size_t size) |
Define new[] operator for 'array' memory allocation. More... | |
void | operator delete (void *ptr) |
Define delete operator for memory deallocation. More... | |
void | operator delete[] (void *ptr) |
Define delete[] operator for memory deallocation. More... | |
void * | operator new (size_t size, void *place) |
Define new operator. More... | |
void | operator delete (void *ptr, void *place) |
Define delete operator. More... | |
void * | operator new (size_t size, CObjectMemoryPool *place) |
Define new operator using memory pool. More... | |
void | operator delete (void *ptr, CObjectMemoryPool *place) |
Define delete operator. More... | |
virtual void | DebugDump (CDebugDumpContext ddc, unsigned int depth) const |
Define method for dumping debug information. More... | |
Public Member Functions inherited from CDebugDumpable | |
CDebugDumpable (void) | |
virtual | ~CDebugDumpable (void) |
void | DebugDumpText (ostream &out, const string &bundle, unsigned int depth) const |
void | DebugDumpFormat (CDebugDumpFormatter &ddf, const string &bundle, unsigned int depth) const |
void | DumpToConsole (void) const |
Protected Member Functions | |
virtual | ~CThreadPool_ServiceThread (void) |
Destructor. Will be called from CRef. More... | |
Protected Member Functions inherited from CThread | |
virtual void | OnExit (void) |
Override this to execute finalization code. More... | |
virtual | ~CThread (void) |
To be called only internally! NOTE: destructor of the derived (user-provided) class should be declared "protected", too! More... | |
TThreadHandle | GetThreadHandle () |
Protected Member Functions inherited from CObject | |
virtual void | DeleteThis (void) |
Virtual method "deleting" this object. More... | |
Private Member Functions | |
virtual void * | Main (void) |
Main thread execution. More... | |
void | x_Idle (void) |
Do "idle" work when thread is not busy executing exclusive tasks. More... | |
Private Attributes | |
CRef< CThreadPool_Impl > | m_Pool |
Pool owning this thread. More... | |
CSemaphore | m_IdleTrigger |
Semaphore for idle sleeping. More... | |
atomic< bool > | m_Finishing |
If finishing of the thread is already requested. More... | |
atomic< bool > | m_Finished |
If the thread has already finished its Main() method. More... | |
CRef< CThreadPool_Task > | m_CurrentTask |
Currently executing exclusive task. More... | |
CAtomicCounter | m_NeedCallController |
Flag indicating that thread should pass eOther event to the controller. More... | |
CFastMutex | m_FastMutex |
General-use mutex for very (very!) trivial ops. More... | |
Additional Inherited Members | |
Public Types inherited from CThread | |
enum | ERunMode { fRunDefault = 0x00 , fRunDetached = 0x01 , fRunBound = 0x10 , fRunUnbound = 0x20 , fRunNice = 0x40 , fRunAllowST = 0x100 , fRunCloneRequestContext = 0x200 } |
Which mode should the thread run in. More... | |
typedef int | TRunMode |
Bitwise OR'd flags for thread creation passed to Run(). More... | |
typedef unsigned int | TID |
Get ID of current thread. More... | |
Public Types inherited from CObject | |
enum | EAllocFillMode { eAllocFillNone = 1 , eAllocFillZero , eAllocFillPattern } |
Control filling of newly allocated memory. More... | |
typedef CObjectCounterLocker | TLockerType |
Default locker type for CRef. More... | |
typedef atomic< Uint8 > | TCounter |
Counter type is CAtomiCounter. More... | |
typedef Uint8 | TCount |
Alias for value type of counter. More... | |
Static Public Member Functions inherited from CThread | |
static void | Exit (void *exit_data) |
Cancel current thread. More... | |
static TID | GetSelf (void) |
static bool | IsMain (void) |
static CThread * | GetCurrentThread (void) |
Get current CThread object (or NULL, if main thread) More... | |
static void | GetSystemID (TThreadSystemID *id) |
Get system ID of the current thread - for internal use only. More... | |
static unsigned int | GetThreadsCount () |
Get total amount of threads This amount does not contain main thread. More... | |
static void | SetCurrentThreadName (const CTempString &) |
Set name for the current thread. More... | |
static void | InitializeMainThreadId (void) |
Initialize main thread's TID. More... | |
static bool | IsAppExiting (void) |
Check if the application is exiting (entered the destructor). More... | |
static void | SetWaitForAllThreadsTimeout (const CTimeout &timeout) |
Set timeout for stopping all threads on application exit. More... | |
Static Public Member Functions inherited from CObject | |
static NCBI_XNCBI_EXPORT void | ThrowNullPointerException (void) |
Define method to throw null pointer exception. More... | |
static NCBI_XNCBI_EXPORT void | ThrowNullPointerException (const type_info &type) |
static EAllocFillMode | GetAllocFillMode (void) |
static void | SetAllocFillMode (EAllocFillMode mode) |
static void | SetAllocFillMode (const string &value) |
Set mode from configuration parameter value. More... | |
Static Public Member Functions inherited from CDebugDumpable | |
static void | EnableDebugDump (bool on) |
Static Public Attributes inherited from CObject | |
static const TCount | eCounterBitsCanBeDeleted = 1 << 0 |
Define possible object states. More... | |
static const TCount | eCounterBitsInPlainHeap = 1 << 1 |
Heap signature was found. More... | |
static const TCount | eCounterBitsPlaceMask |
Mask for 'in heap' state flags. More... | |
static const int | eCounterStep = 1 << 2 |
Skip over the "in heap" bits. More... | |
static const TCount | eCounterValid = TCount(1) << (sizeof(TCount) * 8 - 2) |
Minimal value for valid objects (reference counter is zero) Must be a single bit value. More... | |
static const TCount | eCounterStateMask |
Valid object, and object in heap. More... | |
Thread used in pool for different internal needs: execution of exclusive tasks and passing events to controller.
Definition at line 506 of file thread_pool.cpp.
CThreadPool_ServiceThread::CThreadPool_ServiceThread | ( | CThreadPool_Impl * | pool | ) |
Constructor.
pool | ThreadPool owning this thread |
Definition at line 1076 of file thread_pool.cpp.
References _ASSERT, kNeedCallController_Shift, m_NeedCallController, and CAtomicCounter::Set().
|
protectedvirtual |
Destructor. Will be called from CRef.
Definition at line 1087 of file thread_pool.cpp.
|
inline |
Check if this thread have already finished or not.
Definition at line 1091 of file thread_pool.cpp.
References m_Finished.
Referenced by CThreadPool_Impl::x_HasNoThreads().
|
privatevirtual |
Main thread execution.
Implements CThread.
Definition at line 1129 of file thread_pool.cpp.
References CThreadPool_Impl::CanDoExclusiveTask(), CThreadPool_Task::eCanceled, CThreadPool_Task::eExecuting, CThreadPool_Task::Execute(), CThreadPool::fExecuteQueuedTasks, CThreadPool_Impl::SExclusiveTaskInfo::flags, CThreadPool_Guard::Guard(), CThreadPool_Impl::IsAborted(), CThreadPool_Task::IsCancelRequested(), CRef< C, Locker >::IsNull(), m_CurrentTask, m_FastMutex, m_Finished, m_Finishing, m_IdleTrigger, m_Pool, NCBI_CATCH_ALL_X, NULL, CThreadPool_Guard::Release(), CThreadPool_Impl::RequestSuspend(), CThreadPool_Impl::ResumeWork(), s_ConvertTaskResult(), CThreadPool_Impl::sx_RequestToCancel(), CThreadPool_Impl::sx_SetTaskStatus(), CThreadPool_Impl::SExclusiveTaskInfo::task, CThreadPool_Impl::ThreadStateChanged(), CThreadPool_Impl::TryGetExclusiveTask(), CSemaphore::Wait(), and x_Idle().
|
inline |
Tell the thread that controller should handle eOther event.
Definition at line 636 of file thread_pool.cpp.
References CAtomicCounter::Add(), kNeedCallController_Shift, m_NeedCallController, and WakeUp().
Referenced by CThreadPool_Impl::CallControllerOther().
|
inline |
Request finishing of the thread.
Definition at line 1112 of file thread_pool.cpp.
References m_CurrentTask, m_FastMutex, m_Finishing, CRef< C, Locker >::NotNull(), CThreadPool_Impl::sx_RequestToCancel(), and WakeUp().
Referenced by CThreadPool_Impl::Abort().
|
inline |
Wake up from idle waiting or waiting of pool preparing exclusive environment.
Definition at line 630 of file thread_pool.cpp.
References m_IdleTrigger, and CSemaphore::Post().
Referenced by NeedCallController(), CThreadPool_Impl::RequestExclusiveExecution(), RequestToFinish(), and CThreadPool_Impl::ThreadStateChanged().
|
inlineprivate |
Do "idle" work when thread is not busy executing exclusive tasks.
Definition at line 1097 of file thread_pool.cpp.
References _ASSERT, CAtomicCounter::Add(), CThreadPool_Impl::CallController(), eNegative, CThreadPool_Controller::eOther, CTimeSpan::GetCompleteSeconds(), CTimeSpan::GetNanoSecondsAfterSecond(), CThreadPool_Impl::GetSafeSleepTime(), CTimeSpan::GetSign(), kNeedCallController_Shift, m_IdleTrigger, m_NeedCallController, m_Pool, and CSemaphore::TryWait().
Referenced by Main().
|
private |
Currently executing exclusive task.
Definition at line 549 of file thread_pool.cpp.
Referenced by Main(), and RequestToFinish().
|
mutableprivate |
General-use mutex for very (very!) trivial ops.
Definition at line 553 of file thread_pool.cpp.
Referenced by Main(), and RequestToFinish().
|
private |
If the thread has already finished its Main() method.
Definition at line 547 of file thread_pool.cpp.
Referenced by IsFinished(), and Main().
|
private |
If finishing of the thread is already requested.
Definition at line 545 of file thread_pool.cpp.
Referenced by Main(), and RequestToFinish().
|
private |
Semaphore for idle sleeping.
Definition at line 543 of file thread_pool.cpp.
|
private |
Flag indicating that thread should pass eOther event to the controller.
Definition at line 551 of file thread_pool.cpp.
Referenced by CThreadPool_ServiceThread(), NeedCallController(), and x_Idle().
|
private |
Pool owning this thread.
Definition at line 541 of file thread_pool.cpp.