From eb35e4cac7a6a239392970741bf255011a13ec0e Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Sun, 30 Oct 2011 10:29:19 +0100 Subject: [PATCH] cec: wait for messages to be transmitted before continueing in CCECProcessor::Transmit() --- src/lib/AdapterCommunication.cpp | 2 ++ src/lib/AdapterCommunication.h | 2 ++ src/lib/CECProcessor.cpp | 9 +++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) 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) { -- 2.34.1