fixed - no more delay up to 2 seconds when exiting libCEC
authorLars Op den Kamp <lars@opdenkamp.eu>
Sun, 7 Oct 2012 15:08:42 +0000 (17:08 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Sun, 7 Oct 2012 15:08:42 +0000 (17:08 +0200)
src/lib/CECInputBuffer.h
src/lib/CECProcessor.cpp
src/lib/LibCEC.cpp
src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp
src/lib/adapter/Pulse-Eight/USBCECAdapterMessageQueue.cpp
src/lib/platform/util/buffer.h

index 019cfdd7667f5e29ead4e15398244a01fb1c3fd5..a8679b81b611d4b231edb70ae3dd88954835c05b 100644 (file)
@@ -44,6 +44,13 @@ namespace CEC
     CCECInputBuffer(void) : m_bHasData(false) {}
     virtual ~CCECInputBuffer(void)
     {
+      Broadcast();
+    }
+
+    void Broadcast(void)
+    {
+      PLATFORM::CLockObject lock(m_mutex);
+      m_bHasData = true;
       m_condition.Broadcast();
     }
 
index 54fea57f0cb4e4a7961c7677bff8e601dbdda2e9..ad41d3c5f552fc5b854f556d732c2d074c387205 100644 (file)
@@ -104,6 +104,8 @@ void CCECProcessor::Close(void)
   SetCECInitialised(false);
 
   // stop the processor
+  StopThread(-1);
+  m_inBuffer.Broadcast();
   StopThread();
 
   // close the connection
@@ -222,7 +224,7 @@ void *CCECProcessor::Process(void)
     if (m_inBuffer.Pop(command, CEC_PROCESSOR_SIGNAL_WAIT_TIME))
       ProcessCommand(command);
 
-    if (CECInitialised())
+    if (CECInitialised() && !IsStopped())
     {
       // check clients for keypress timeouts
       m_libcec->CheckKeypressTimeout();
index 9ff5e146b6d06ff7c4607890b0eceb45ddf83f63..904204a2c8e97a1b7dd01f43ff34125966777382 100644 (file)
@@ -418,7 +418,7 @@ CCECClient *CLibCEC::RegisterClient(libcec_configuration &configuration)
 
 void CLibCEC::UnregisterClients(void)
 {
-  if (m_cec)
+  if (m_cec && m_cec->IsRunning())
     m_cec->UnregisterClients();
 
   m_clients.clear();
index 7fa78f73638b96eff4e9ace948a258f57247affd..9c6743f0851ec8c7a241cddec6c3e6b39418979b 100644 (file)
@@ -284,7 +284,8 @@ void *CUSBCECAdapterCommunication::Process(void)
     }
 
     /* TODO sleep 5 ms so other threads can get a lock */
-    Sleep(5);
+    if (!IsStopped())
+      Sleep(5);
   }
 
   m_adapterMessageQueue->Clear();
@@ -738,6 +739,7 @@ void CAdapterEepromWriteThread::Stop(void)
     CLockObject lock(m_mutex);
     if (m_iScheduleEepromWrite > 0)
       m_com->LIB_CEC->AddLog(CEC_LOG_WARNING, "write thread stopped while a write was queued");
+    m_bWrite = true;
     m_condition.Signal();
   }
   StopThread();
@@ -751,6 +753,8 @@ void *CAdapterEepromWriteThread::Process(void)
     if ((m_iScheduleEepromWrite > 0 && m_iScheduleEepromWrite < GetTimeMs()) ||
         m_condition.Wait(m_mutex, m_bWrite, 100))
     {
+      if (IsStopped())
+        break;
       m_bWrite = false;
       if (m_com->m_commands->WriteEEPROM())
       {
index 35faeb71890b73892fb7a5c67b17b532b2a3d625..1b14f445f30e9bfc43afbef5304296d3277cb619 100644 (file)
@@ -296,8 +296,9 @@ CCECAdapterMessageQueue::CCECAdapterMessageQueue(CUSBCECAdapterCommunication *co
 
 CCECAdapterMessageQueue::~CCECAdapterMessageQueue(void)
 {
+  StopThread(-1);
   Clear();
-  StopThread(0);
+  StopThread();
   delete m_incomingAdapterMessage;
 }
 
index 4b57a29c7d340e180f04f29222eaae9d140f7802..30fcac84167d6ec483b7d37e6d43fe535d1cd4f5 100644 (file)
@@ -54,6 +54,7 @@ namespace PLATFORM
         CLockObject lock(m_mutex);
         while (!m_buffer.empty())
           m_buffer.pop();
+        m_bHasMessages = true;
         m_condition.Broadcast();
       }
 
@@ -94,11 +95,11 @@ namespace PLATFORM
         }
 
         // pop the first item
+        m_bHasMessages = !m_buffer.empty();
         if (!m_buffer.empty())
         {
           entry = m_buffer.front();
           m_buffer.pop();
-          m_bHasMessages = !m_buffer.empty();
           bReturn = true;
         }
         return bReturn;