+
+CThread::CThread(void) :
+ m_bRunning(false),
+ m_bStop(false)
+{
+}
+
+CThread::~CThread(void)
+{
+ m_bStop = true;
+ pthread_join(m_thread, NULL);
+}
+
+bool CThread::CreateThread(void)
+{
+ bool bReturn(false);
+
+ if (!m_bRunning && pthread_create(&m_thread, NULL, (void *(*) (void *))&CThread::ThreadHandler, (void *)this) == 0)
+ {
+ m_bRunning = true;
+ pthread_detach(m_thread);
+ bReturn = true;
+ }
+
+ return bReturn;
+}
+
+void *CThread::ThreadHandler(CThread *thread)
+{
+ if (thread)
+ return thread->Process();
+ return NULL;
+}
+
+bool CThread::StopThread(bool bWaitForExit /* = true */)
+{
+ m_bStop = true;
+ if (bWaitForExit)
+ pthread_join(m_thread, NULL);
+}