X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FCECProcessor.cpp;h=3fb3bc299a3a5782fb2699293a4b982b12ad5e60;hb=cd505625984870e36f98323209d3c2d7273e3266;hp=d5ee321ce90954fa485cd33a978dd610c55f003a;hpb=b9eea66dd7e19a4baf9e89f4fd6b3c2f281ba7a7;p=deb_libcec.git diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index d5ee321..3fb3bc2 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; @@ -210,17 +223,17 @@ bool CCECProcessor::Transmit(const cec_command &data) return bReturn; } } - } - if (data.ack_timeout > 0) - { - bool bError(false); - if ((bReturn = WaitForAck(&bError, output->size(), data.ack_timeout)) == false) - m_controller->AddLog(CEC_LOG_ERROR, "did not receive ack"); - } - else - { - bReturn = true; + if (data.ack_timeout > 0) + { + bool bError(false); + if ((bReturn = WaitForAck(&bError, output->size(), data.ack_timeout)) == false) + m_controller->AddLog(CEC_LOG_ERROR, "did not receive ack"); + } + else + { + bReturn = true; + } } return bReturn;