cec: fixed - ensure that the correct libCEC version is set after initialising the...
[deb_libcec.git] / src / lib / platform / threads / threads.h
index 1d14f8cea32560befc14f24267df7e07a55bfbb5..ead0ebdcb18c5e53525f60bb1882cdf9f12fabe6 100644 (file)
@@ -41,13 +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(0);
       void *retVal;
-      ThreadsWait(m_thread, &retVal);
+      if (m_thread)
+        ThreadsWait(m_thread, &retVal);
+      #if defined(__WINDOWS__)
+      (void *)retVal; //"unreferenced local variable" warning
+      #endif
     }
 
     static void *ThreadHandler(CThread *thread)
@@ -90,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<CThread *>(this))))
         {
-          m_bStop = false;
-          if (ThreadsCreate(m_thread, CThread::ThreadHandler, ((void*)static_cast<CThread *>(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;
     }
 
@@ -142,13 +147,13 @@ namespace PLATFORM
 
   protected:
     void SetRunning(bool bSetTo);
+    CMutex           m_threadMutex;
 
   private:
     bool             m_bStop;
     bool             m_bRunning;
     bool             m_bStopped;
     CCondition<bool> m_threadCondition;
-    CMutex           m_threadMutex;
     thread_t         m_thread;
   };
 };