cec: fixed - mutex in CAdapterCommunication::Close() and CAdapterCommunication::Open()
authorLars Op den Kamp <lars@opdenkamp.eu>
Sun, 30 Oct 2011 09:01:29 +0000 (10:01 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Sun, 30 Oct 2011 09:01:29 +0000 (10:01 +0100)
src/lib/AdapterCommunication.cpp
src/lib/AdapterCommunication.h

index 743f00d66e6caefe6bf0d079248a641e7d691bd3..c05abdf8421f3d14d2a7d9a3d4cd3def70d66543 100644 (file)
@@ -119,6 +119,7 @@ CAdapterCommunication::~CAdapterCommunication(void)
 
 bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint32_t iTimeoutMs /* = 10000 */)
 {
+  CLockObject lock(&m_mutex);
   if (!m_port)
   {
     m_controller->AddLog(CEC_LOG_ERROR, "port is NULL");
@@ -159,6 +160,7 @@ bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38
 
 void CAdapterCommunication::Close(void)
 {
+  CLockObject lock(&m_mutex);
   StopThread();
 
   m_rcvCondition.Broadcast();
@@ -201,7 +203,7 @@ bool CAdapterCommunication::ReadFromDevice(uint32_t iTimeout)
 
 void CAdapterCommunication::AddData(uint8_t *data, uint8_t iLen)
 {
-  CLockObject lock(&m_bufferMutex);
+  CLockObject lock(&m_mutex);
   for (unsigned int iPtr = 0; iPtr < iLen; iPtr++)
     m_inBuffer.Push(data[iPtr]);
 
@@ -235,7 +237,7 @@ bool CAdapterCommunication::Write(CCECAdapterMessagePtr data)
 
 bool CAdapterCommunication::Read(CCECAdapterMessage &msg, uint32_t iTimeout)
 {
-  CLockObject lock(&m_bufferMutex);
+  CLockObject lock(&m_mutex);
 
   msg.clear();
   uint64_t iNow = GetTimeMs();
@@ -249,7 +251,7 @@ bool CAdapterCommunication::Read(CCECAdapterMessage &msg, uint32_t iTimeout)
     uint8_t buf = 0;
     if (!m_inBuffer.Pop(buf))
     {
-      if (!m_rcvCondition.Wait(&m_bufferMutex, iTarget - iNow))
+      if (!m_rcvCondition.Wait(&m_mutex, iTarget - iNow))
         return false;
     }
 
index 71688301351c89d84428d63b31d319d90fc76706..29b716a078553fbb63cefa6cce57e7f67fd09d17 100644 (file)
@@ -96,7 +96,7 @@ namespace CEC
     CLibCEC *                        m_controller;
     CecBuffer<uint8_t>               m_inBuffer;
     CecBuffer<CCECAdapterMessagePtr> m_outBuffer;
-    CMutex                           m_bufferMutex;
+    CMutex                           m_mutex;
     CCondition                       m_rcvCondition;
   };
 };