From: Lars Op den Kamp Date: Sun, 7 Oct 2012 15:08:42 +0000 (+0200) Subject: fixed - no more delay up to 2 seconds when exiting libCEC X-Git-Tag: upstream/2.2.0~1^2~17^2^2~16 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=aaff5ceeded22bee9e50cfebb638e8f83daec45d;p=deb_libcec.git fixed - no more delay up to 2 seconds when exiting libCEC --- diff --git a/src/lib/CECInputBuffer.h b/src/lib/CECInputBuffer.h index 019cfdd..a8679b8 100644 --- a/src/lib/CECInputBuffer.h +++ b/src/lib/CECInputBuffer.h @@ -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(); } diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 54fea57..ad41d3c 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -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(); diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 9ff5e14..904204a 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -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(); diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp index 7fa78f7..9c6743f 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp @@ -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()) { diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterMessageQueue.cpp b/src/lib/adapter/Pulse-Eight/USBCECAdapterMessageQueue.cpp index 35faeb7..1b14f44 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterMessageQueue.cpp +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterMessageQueue.cpp @@ -296,8 +296,9 @@ CCECAdapterMessageQueue::CCECAdapterMessageQueue(CUSBCECAdapterCommunication *co CCECAdapterMessageQueue::~CCECAdapterMessageQueue(void) { + StopThread(-1); Clear(); - StopThread(0); + StopThread(); delete m_incomingAdapterMessage; } diff --git a/src/lib/platform/util/buffer.h b/src/lib/platform/util/buffer.h index 4b57a29..30fcac8 100644 --- a/src/lib/platform/util/buffer.h +++ b/src/lib/platform/util/buffer.h @@ -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;