From: Lars Op den Kamp Date: Thu, 31 May 2012 22:30:07 +0000 (+0200) Subject: cec: hold a lock when changing the ackmask in CUSBCECAdapterCommunication::Open X-Git-Tag: upstream/2.2.0~1^2~23^2^2~17 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c6f01e113d244a0c7ab22a3c4f1bab55693dd011;p=deb_libcec.git cec: hold a lock when changing the ackmask in CUSBCECAdapterCommunication::Open --- diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index fe40990..0012a53 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -148,9 +148,6 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint m_libcec->AddLog(CEC_LOG_NOTICE, "connection opened"); - // always start by setting the ackmask to 0, to clear previous values - SetAckMask(0); - // mark as initialised SetCECInitialised(true); diff --git a/src/lib/adapter/USBCECAdapterCommunication.cpp b/src/lib/adapter/USBCECAdapterCommunication.cpp index 33eb260..d6d9b5c 100644 --- a/src/lib/adapter/USBCECAdapterCommunication.cpp +++ b/src/lib/adapter/USBCECAdapterCommunication.cpp @@ -66,6 +66,7 @@ CUSBCECAdapterCommunication::CUSBCECAdapterCommunication(IAdapterCommunicationCa for (unsigned int iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++) m_bWaitingForAck[iPtr] = false; m_port = new CSerialPort(strPort, iBaudRate); + m_commands = new CUSBCECAdapterCommands(this); } CUSBCECAdapterCommunication::~CUSBCECAdapterCommunication(void) @@ -76,6 +77,13 @@ CUSBCECAdapterCommunication::~CUSBCECAdapterCommunication(void) DELETE_AND_NULL(m_port); } +void CUSBCECAdapterCommunication::ResetMessageQueue(void) +{ + DELETE_AND_NULL(m_adapterMessageQueue); + m_adapterMessageQueue = new CCECAdapterMessageQueue(this); + m_adapterMessageQueue->CreateThread(); +} + bool CUSBCECAdapterCommunication::Open(uint32_t iTimeoutMs /* = CEC_DEFAULT_CONNECT_TIMEOUT */, bool bSkipChecks /* = false */, bool bStartListening /* = true */) { bool bConnectionOpened(false); @@ -96,15 +104,7 @@ bool CUSBCECAdapterCommunication::Open(uint32_t iTimeoutMs /* = CEC_DEFAULT_CONN return true; } - /* adapter commands */ - if (!m_commands) - m_commands = new CUSBCECAdapterCommands(this); - - if (!m_adapterMessageQueue) - { - m_adapterMessageQueue = new CCECAdapterMessageQueue(this); - m_adapterMessageQueue->CreateThread(); - } + ResetMessageQueue(); /* try to open the connection */ CStdString strError; @@ -145,6 +145,9 @@ bool CUSBCECAdapterCommunication::Open(uint32_t iTimeoutMs /* = CEC_DEFAULT_CONN ClearInputBytes(); } + // always start by setting the ackmask to 0, to clear previous values + SetAckMask(0); + if (!CreateThread()) { bConnectionOpened = false; @@ -493,11 +496,15 @@ bool CUSBCECAdapterCommunication::StartBootloader(void) bool CUSBCECAdapterCommunication::SetAckMask(uint16_t iMask) { - if (m_iAckMask == iMask) - return true; + { + CLockObject lock(m_mutex); + if (m_iAckMask == iMask) + return true; + } if (IsOpen() && m_commands->SetAckMask(iMask)) { + CLockObject lock(m_mutex); m_iAckMask = iMask; return true; } @@ -508,6 +515,7 @@ bool CUSBCECAdapterCommunication::SetAckMask(uint16_t iMask) uint16_t CUSBCECAdapterCommunication::GetAckMask(void) { + CLockObject lock(m_mutex); return m_iAckMask; } diff --git a/src/lib/adapter/USBCECAdapterCommunication.h b/src/lib/adapter/USBCECAdapterCommunication.h index 7409e86..0177f08 100644 --- a/src/lib/adapter/USBCECAdapterCommunication.h +++ b/src/lib/adapter/USBCECAdapterCommunication.h @@ -157,6 +157,11 @@ namespace CEC */ void MarkAsWaiting(const cec_logical_address dest); + /*! + * @brief Clear and reset the message queue. + */ + void ResetMessageQueue(void); + PLATFORM::ISocket * m_port; /**< the com port connection */ PLATFORM::CMutex m_mutex; /**< mutex for changes in this class */ uint8_t m_iLineTimeout; /**< the current line timeout on the CEC line */