X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Fplatform%2Fthreads%2Fthreads.h;h=ead0ebdcb18c5e53525f60bb1882cdf9f12fabe6;hb=5f2f3609d7ee857ac7e5d03600fbd735e99c892f;hp=c730da8256743c8132f7ef69279a365aa892854d;hpb=78d138bd56ecc5a5c2184415af8dd1778dd71337;p=deb_libcec.git diff --git a/src/lib/platform/threads/threads.h b/src/lib/platform/threads/threads.h index c730da8..ead0ebd 100644 --- a/src/lib/platform/threads/threads.h +++ b/src/lib/platform/threads/threads.h @@ -41,11 +41,18 @@ namespace PLATFORM CThread(void) : m_bStop(false), m_bRunning(false), - m_bStopped(false) {} + m_bStopped(false), + m_thread(NULL) {} virtual ~CThread(void) { - StopThread(); + StopThread(0); + void *retVal; + if (m_thread) + ThreadsWait(m_thread, &retVal); + #if defined(__WINDOWS__) + (void *)retVal; //"unreferenced local variable" warning + #endif } static void *ThreadHandler(CThread *thread) @@ -88,18 +95,18 @@ namespace PLATFORM virtual bool CreateThread(bool bWait = true) { - bool bReturn(false); - CLockObject lock(m_threadMutex); - if (!IsRunning()) + bool bReturn(false); + CLockObject lock(m_threadMutex); + if (!IsRunning()) + { + m_bStop = false; + if (ThreadsCreate(m_thread, CThread::ThreadHandler, ((void*)static_cast(this)))) { - m_bStop = false; - if (ThreadsCreate(m_thread, CThread::ThreadHandler, ((void*)static_cast(this)))) - { - if (bWait) - m_threadCondition.Wait(m_threadMutex, m_bRunning); - bReturn = true; - } + if (bWait) + m_threadCondition.Wait(m_threadMutex, m_bRunning); + bReturn = true; } + } return bReturn; } @@ -140,13 +147,13 @@ namespace PLATFORM protected: void SetRunning(bool bSetTo); + CMutex m_threadMutex; private: bool m_bStop; bool m_bRunning; bool m_bStopped; CCondition m_threadCondition; - CMutex m_threadMutex; thread_t m_thread; }; };