cec: fixed - wait for the processor thread to start before continueing
authorLars Op den Kamp <lars@opdenkamp.eu>
Sun, 30 Oct 2011 10:28:39 +0000 (11:28 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Sun, 30 Oct 2011 10:28:45 +0000 (11:28 +0100)
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h

index d5ee321ce90954fa485cd33a978dd610c55f003a..277009b83a9621de3a645d78ab195a7f9f03eb34 100644 (file)
@@ -54,6 +54,7 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm
 
 CCECProcessor::~CCECProcessor(void)
 {
+  m_startCondition.Broadcast();
   StopThread();
   m_communication = NULL;
   m_controller = NULL;
@@ -63,6 +64,7 @@ CCECProcessor::~CCECProcessor(void)
 
 bool CCECProcessor::Start(void)
 {
+  CLockObject lock(&m_mutex);
   if (!m_communication || !m_communication->IsOpen())
   {
     m_controller->AddLog(CEC_LOG_ERROR, "connection is closed");
@@ -76,7 +78,14 @@ bool CCECProcessor::Start(void)
   }
 
   if (CreateThread())
+  {
+    if (!m_startCondition.Wait(&m_mutex))
+    {
+      m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
+      return false;
+    }
     return true;
+  }
   else
     m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
 
@@ -85,7 +94,11 @@ bool CCECProcessor::Start(void)
 
 void *CCECProcessor::Process(void)
 {
-  m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
+  {
+    CLockObject lock(&m_mutex);
+    m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
+    m_startCondition.Signal();
+  }
 
   cec_command           command;
   CCECAdapterMessage    msg;
index 0d8a21f188e9b961960eaf73956c1bae0bd81022..fc9a2fa99123c18ddb6edbd07cead37e4d909356 100644 (file)
@@ -86,6 +86,7 @@ namespace CEC
       CecBuffer<CCECAdapterMessagePtr> m_frameBuffer;
       std::string                      m_strDeviceName;
       CMutex                           m_mutex;
+      CCondition                       m_startCondition;
       CAdapterCommunication           *m_communication;
       CLibCEC                         *m_controller;
       bool                             m_bMonitor;