From: Lars Op den Kamp Date: Sun, 30 Oct 2011 09:29:19 +0000 (+0100) Subject: cec: wait for messages to be transmitted before continueing in CCECProcessor::Transmit() X-Git-Tag: upstream/2.2.0~1^2~178 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=eb35e4cac7a6a239392970741bf255011a13ec0e;p=deb_libcec.git cec: wait for messages to be transmitted before continueing in CCECProcessor::Transmit() --- diff --git a/src/lib/AdapterCommunication.cpp b/src/lib/AdapterCommunication.cpp index c05abdf..4845f57 100644 --- a/src/lib/AdapterCommunication.cpp +++ b/src/lib/AdapterCommunication.cpp @@ -215,6 +215,7 @@ void CAdapterCommunication::WriteNextCommand(void) CCECAdapterMessagePtr msg; if (m_outBuffer.Pop(msg)) { + CLockObject lock(&msg->mutex); if (m_port->Write(msg) != (int32_t) msg.get()->size()) { CStdString strError; @@ -226,6 +227,7 @@ void CAdapterCommunication::WriteNextCommand(void) m_controller->AddLog(CEC_LOG_DEBUG, "command sent"); CCondition::Sleep((uint32_t) msg.get()->size() * (uint32_t)24 /*data*/ + (uint32_t)5 /*start bit (4.5 ms)*/); } + msg->condition.Signal(); } } diff --git a/src/lib/AdapterCommunication.h b/src/lib/AdapterCommunication.h index 5e099d8..a82f32c 100644 --- a/src/lib/AdapterCommunication.h +++ b/src/lib/AdapterCommunication.h @@ -61,6 +61,8 @@ namespace CEC void push_escaped(int16_t byte); cec_datapacket packet; + CMutex mutex; + CCondition condition; private: CCECAdapterMessage &operator =(const CCECAdapterMessage &msg); diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 54794c3..350958f 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -195,8 +195,13 @@ bool CCECProcessor::Transmit(const cec_command &data, bool bWaitForAck /* = true CCECAdapterMessagePtr output(new CCECAdapterMessage(data)); CLockObject lock(&m_mutex); - if (!m_communication || !m_communication->Write(output)) - return bReturn; + { + CLockObject msgLock(&output->mutex); + if (!m_communication || !m_communication->Write(output)) + return bReturn; + else + output->condition.Wait(&output->mutex); + } if (bWaitForAck) {