From: Lars Op den Kamp Date: Fri, 17 Feb 2012 10:14:08 +0000 (+0100) Subject: cec: cleaned up CCECBusDevice::GetStatus() X-Git-Tag: upstream/2.2.0~1^2~35^2~14 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=ba427965a1ac1d555e292e577b990ecd467e3ca8;p=deb_libcec.git cec: cleaned up CCECBusDevice::GetStatus() --- diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index a0d612e..3c39371 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -86,6 +86,7 @@ bool CCECBusDevice::HandleCommand(const cec_command &command) CLockObject lock(m_mutex); m_iLastActive = GetTimeMs(); + /* don't call GetStatus() here, just read the value with the mutex locked */ if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC) m_deviceStatus = CEC_DEVICE_STATUS_PRESENT; @@ -439,20 +440,27 @@ bool CCECBusDevice::NeedsPoll(void) cec_bus_device_status CCECBusDevice::GetStatus(bool bForcePoll /* = false */) { - CLockObject lock(m_mutex); - if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC && - (m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN || bForcePoll)) + cec_bus_device_status status(CEC_DEVICE_STATUS_UNKNOWN); + bool bNeedsPoll(false); + + { + CLockObject lock(m_mutex); + status = m_deviceStatus; + bNeedsPoll = (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC && + (m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN || bForcePoll)); + } + + if (bNeedsPoll) { - lock.Unlock(); bool bPollAcked(false); - if (bForcePoll || NeedsPoll()) + if (bNeedsPoll || NeedsPoll()) bPollAcked = m_processor->PollDevice(m_iLogicalAddress); - lock.Lock(); - m_deviceStatus = bPollAcked ? CEC_DEVICE_STATUS_PRESENT : CEC_DEVICE_STATUS_NOT_PRESENT; + status = bPollAcked ? CEC_DEVICE_STATUS_PRESENT : CEC_DEVICE_STATUS_NOT_PRESENT; + SetDeviceStatus(status); } - return m_deviceStatus; + return status; } //@}