![]() |
KSquare Utilities
|
The base class to be used any thread. More...
#include <KKThread.h>
Inheritance diagram for KKB::KKThread:Public Types | |
| typedef KKThread * | KKThreadPtr |
| enum | ThreadPriority : int { ThreadPriority::Null, ThreadPriority::Low, ThreadPriority::Normal, ThreadPriority::High } |
| enum | ThreadStatus : int { ThreadStatus::Null, ThreadStatus::NotStarted, ThreadStatus::Starting, ThreadStatus::Running, ThreadStatus::Stopping, ThreadStatus::Stopped } |
Public Member Functions | |
| KKThread (const KKStr &_threadName, KKThreadManagerPtr _threadManager, MsgQueuePtr _msgQueue) | |
| virtual | ~KKThread () |
| void | AddShutdownPrerequistite (KKThreadPtr _thread) |
| Specify threads that must stop before this thread is started. More... | |
| void | AddStartPrerequistite (KKThreadPtr _thread) |
| Specify threads that must start before this thread is started. More... | |
| VolConstBool & | CancelFlag () const |
| bool | Crashed () const |
| void | Crashed (bool _crashed) |
| const KKStr & | ExceptionText () const |
| void | ExceptionText (const KKStr &_exceptionText) |
| KKStrListPtr | GetMsgs () |
| void | Kill () |
| stops the running thread and frees the thread handle More... | |
| kkint32 | MemoryConsumedEstimated () |
| KKB::MsgQueuePtr | MsgQueue () |
| bool | OkToShutdown () const |
| bool | OkToStart () const |
| virtual void | Run () |
| VolConstBool & | ShutdownFlag () const |
| void | ShutdownThread () |
| void | Start (ThreadPriority _priority, bool &successful) |
| ThreadStatus | Status () const |
| void | Status (ThreadStatus _status) |
| const KKStr & | StatusStr () const |
| VolConstBool & | TerminateFlag () const |
| virtual void | TerminateFlagChanged () |
| Will be called whenever the value of 'terminateFlag' is changed; derived classes should override this method if they need to be aware that the terminaeFlag has changed. This give them a chance to let other objects/methods know that the flag has changed. More... | |
| void | TerminateThread () |
| kkint32 | ThreadId () const |
| const KKStr & | ThreadName () const |
| bool | ThreadStillProcessing () const |
| void | WaitForThreadToStop (kkuint32 maxTimeToWait) |
| Called by separate thread; will stay in loop until the thread controlled by this instance shutdown or it waited the 'maxTimeToWait'. More... | |
Static Public Member Functions | |
| static const KKStr & | ThreadStatusToStr (ThreadStatus) |
Protected Member Functions | |
| void | AddMsg (KKStrPtr msg) |
| void | AddMsg (const KKStr &msg) |
| bool | ShutdownOrTerminateRequested () |
| bool | ThereIsACircularReferenceShutdown (KKThreadPtr _thread) const |
| bool | ThereIsACircularReferenceStart (KKThreadPtr _thread) const |
The base class to be used any thread.
This will be the base class for each one of the different types of processing.
Definition at line 27 of file KKThread.h.
| typedef KKThread* KKB::KKThread::KKThreadPtr |
Definition at line 30 of file KKThread.h.
|
strong |
| Enumerator | |
|---|---|
| Null | |
| Low | |
| Normal | |
| High | |
Definition at line 32 of file KKThread.h.
|
strong |
| Enumerator | |
|---|---|
| Null | |
| NotStarted | |
| Starting | |
| Running | |
| Stopping | |
| Stopped | |
Definition at line 39 of file KKThread.h.
| KKThread::KKThread | ( | const KKStr & | _threadName, |
| KKThreadManagerPtr | _threadManager, | ||
| MsgQueuePtr | _msgQueue | ||
| ) |
Definition at line 83 of file KKThread.cpp.
References KKB::KKStr::KKStr(), Normal, and NotStarted.
Referenced by KKB::KKThreadManager::KKThreadManager().
|
virtual |
Definition at line 109 of file KKThread.cpp.
|
protected |
Taking ownership of 'msg' and will append to 'msgQueue'.
Definition at line 154 of file KKThread.cpp.
References KKB::MsgQueue::AddMsg().
|
protected |
A copy of the message 'msg' will be added to the end of msgQueue.
Definition at line 174 of file KKThread.cpp.
References KKB::MsgQueue::AddMsg(), KKB::KKStr::Concat(), KKB::KKStr::KKStr(), KKB::KKStr::Len(), KKB::osGetLocalDateTime(), KKB::osGetThreadId(), and KKB::DateTime::Time().
Referenced by Run().
| void KKThread::AddShutdownPrerequistite | ( | KKThreadPtr | _thread | ) |
Specify threads that must stop before this thread is started.
This method can be called multiple times; the information is used by the 'KKTHreadManager' instance to control the orderly shutdown of the controlling 'KKTHreadManager' instance.
| [in] | _thread | A thread that needs to be in the 'Stopped' status before this thread can be shutdown; we do NOT take ownership. |
Definition at line 510 of file KKThread.cpp.
References KKB::KKThreadList::KKThreadList().
| void KKThread::AddStartPrerequistite | ( | KKThreadPtr | _thread | ) |
Specify threads that must start before this thread is started.
This method can be called multiple times; the information is used by the 'KKTHreadManager' instance to control the start of the thread.
| [in] | _thread | A thread that needs to be in the 'Running' status before this thread can start; we do NOT take ownership. |
Definition at line 501 of file KKThread.cpp.
References KKB::KKThreadList::KKThreadList().
|
inline |
Another name for 'TerminateFlag'.
Definition at line 60 of file KKThread.h.
|
inline |
Signifies that this thread had to terminate on its own because of an abnormal situation; such as a memory corruption.
Definition at line 62 of file KKThread.h.
Referenced by KKB::KKThreadManager::AnyProcessorsCrashed().
|
inline |
Definition at line 89 of file KKThread.h.
Referenced by KKB::ThreadStartCallBack().
|
inline |
If the overloaded 'Run' method of a derived class generates a exception that is not caught; then the ''ThreadStartCallBack' will catch it and store the related text in this field. In this case the 'Crashed()' method will return 'true'.
Definition at line 66 of file KKThread.h.
|
inline |
Definition at line 90 of file KKThread.h.
References KKB::KKStr::operator=().
Referenced by KKB::ThreadStartCallBack().
| KKStrListPtr KKThread::GetMsgs | ( | ) |
Definition at line 193 of file KKThread.cpp.
References KKB::MsgQueue::GetNextMsg(), and KKB::KKStrList::KKStrList().
| void KKThread::Kill | ( | ) |
stops the running thread and frees the thread handle
Definition at line 427 of file KKThread.cpp.
Referenced by KKB::KKThreadManager::KillAllRunningThreads(), and WaitForThreadToStop().
| kkint32 KKThread::MemoryConsumedEstimated | ( | ) |
Definition at line 117 of file KKThread.cpp.
References KKB::MsgQueue::MemoryConsumedEstimated(), KKB::KKThreadList::MemoryConsumedEstimated(), and KKB::KKStr::MemoryConsumedEstimated().
Referenced by KKB::KKThreadList::MemoryConsumedEstimated().
|
inline |
Definition at line 71 of file KKThread.h.
| bool KKThread::OkToShutdown | ( | ) | const |
Returns 'true' if all shutdown prerequisites are in the 'Stopped' status.
Definition at line 519 of file KKThread.cpp.
References Status(), and Stopped.
Referenced by KKB::KKThreadManager::ShutdownProcessing().
| bool KKThread::OkToStart | ( | ) | const |
Returns 'true' if all start prerequisites are in the 'Running' status.
Definition at line 536 of file KKThread.cpp.
References Running, and Status().
|
virtual |
Reimplemented in KKB::KKThreadManager.
Definition at line 447 of file KKThread.cpp.
References AddMsg().
Referenced by KKB::ThreadStartCallBack().
|
inline |
Indicates that the application wants this thread to complete what work is queued up for it top process. Threads need to monitor this flag; if it goes true they are to complete all processing that is queued up and then shutdown. This is
Definition at line 75 of file KKThread.h.
Referenced by KKB::KKThreadManager::ShutdownProcessing().
|
inlineprotected |
Definition at line 148 of file KKThread.h.
| void KKThread::ShutdownThread | ( | ) |
Call this method to have its thread finish what ever is in the queue and then exit.
Definition at line 231 of file KKThread.cpp.
Referenced by KKB::KKThreadManager::ShutdownProcessing().
| void KKThread::Start | ( | ThreadPriority | _priority, |
| bool & | successful | ||
| ) |
Call this method to start thread; it will call the method "Run".
Definition at line 352 of file KKThread.cpp.
References KKB::KKException::KKException().
|
inline |
Definition at line 72 of file KKThread.h.
Referenced by KKB::KKThreadManager::AllThreadsTerminated(), OkToShutdown(), OkToStart(), and KKB::KKThreadManager::ShutdownProcessing().
|
inline |
Definition at line 91 of file KKThread.h.
Referenced by KKB::ThreadStartCallBack().
|
inline |
Definition at line 73 of file KKThread.h.
References ThreadStatusToStr().
|
inline |
Indicates that thread is to stop processing ASAP, release any resources it holds and terminate. Threads need to monitor this flag; if it goes 'true' they need to terminate ASAP releasing all allocated resources. Typically set to true when user request to cancel processing.
Definition at line 80 of file KKThread.h.
|
virtual |
Will be called whenever the value of 'terminateFlag' is changed; derived classes should override this method if they need to be aware that the terminaeFlag has changed. This give them a chance to let other objects/methods know that the flag has changed.
Definition at line 216 of file KKThread.cpp.
Referenced by TerminateThread().
| void KKThread::TerminateThread | ( | ) |
Call this method to have its thread stop right away and exit.
Definition at line 208 of file KKThread.cpp.
References TerminateFlagChanged().
Referenced by KKB::KKThreadManager::TerminateProcessing().
|
protected |
Definition at line 480 of file KKThread.cpp.
References ThereIsACircularReferenceStart().
|
protected |
Definition at line 459 of file KKThread.cpp.
References ThereIsACircularReferenceStart().
Referenced by ThereIsACircularReferenceShutdown(), and ThereIsACircularReferenceStart().
|
inline |
Definition at line 86 of file KKThread.h.
|
inline |
Definition at line 87 of file KKThread.h.
|
static |
Definition at line 144 of file KKThread.cpp.
References KKB::KKStr::Concat(), KKB::KKStr::EmptyStr(), Null, and Stopped.
Referenced by StatusStr().
| bool KKThread::ThreadStillProcessing | ( | ) | const |
| void KKThread::WaitForThreadToStop | ( | kkuint32 | maxTimeToWait | ) |
Called by separate thread; will stay in loop until the thread controlled by this instance shutdown or it waited the 'maxTimeToWait'.
Does not call the 'ShutdownThread' or 'TerminateThread' methods.
| [in] | maxTimeToWait | Will wait 'maxTimeToWait' seconds before giving up on waiting at which point will try to kill thread. |
Definition at line 238 of file KKThread.cpp.
References Kill(), NotStarted, Null, KKB::osGetLocalDateTime(), KKB::osSleepMiliSecs(), Running, KKB::DateTime::Seconds(), Stopped, and Stopping.