From: Lars Op den Kamp Date: Sun, 30 Oct 2011 10:28:39 +0000 (+0100) Subject: cec: fixed - wait for the processor thread to start before continueing X-Git-Tag: upstream/2.2.0~1^2~174 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8b0ee2cc959ab9d0b30c21615c25f6447d1f8566;p=deb_libcec.git cec: fixed - wait for the processor thread to start before continueing --- diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index d5ee321..277009b 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -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; diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index 0d8a21f..fc9a2fa 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -86,6 +86,7 @@ namespace CEC CecBuffer m_frameBuffer; std::string m_strDeviceName; CMutex m_mutex; + CCondition m_startCondition; CAdapterCommunication *m_communication; CLibCEC *m_controller; bool m_bMonitor;