fixed: possible deadlock when inserting or removing a peripheral
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 14 Oct 2011 00:48:47 +0000 (02:48 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 14 Oct 2011 17:48:00 +0000 (19:48 +0200)
xbmc/peripherals/Peripherals.cpp
xbmc/peripherals/Peripherals.h
xbmc/peripherals/bus/PeripheralBus.cpp
xbmc/peripherals/devices/PeripheralCecAdapter.cpp

index 8d68b3f..fd44faa 100644 (file)
@@ -278,26 +278,22 @@ CPeripheral *CPeripherals::CreatePeripheral(CPeripheralBus &bus, const Periphera
   return peripheral;
 }
 
-void CPeripherals::OnDeviceAdded(const CPeripheralBus &bus, const CStdString &strLocation)
+void CPeripherals::OnDeviceAdded(const CPeripheralBus &bus, const CPeripheral &peripheral)
 {
   CGUIDialogPeripheralManager *dialog = (CGUIDialogPeripheralManager *)g_windowManager.GetWindow(WINDOW_DIALOG_PERIPHERAL_MANAGER);
   if (dialog && dialog->IsActive())
     dialog->Update();
 
-  CPeripheral *peripheral = GetByPath(strLocation);
-  if (peripheral)
-    CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(35005), peripheral->DeviceName());
+  CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(35005), peripheral.DeviceName());
 }
 
-void CPeripherals::OnDeviceDeleted(const CPeripheralBus &bus, const CStdString &strLocation)
+void CPeripherals::OnDeviceDeleted(const CPeripheralBus &bus, const CPeripheral &peripheral)
 {
   CGUIDialogPeripheralManager *dialog = (CGUIDialogPeripheralManager *)g_windowManager.GetWindow(WINDOW_DIALOG_PERIPHERAL_MANAGER);
   if (dialog && dialog->IsActive())
     dialog->Update();
 
-  CPeripheral *peripheral = GetByPath(strLocation);
-  if (peripheral)
-    CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(35006), peripheral->DeviceName());
+  CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(35006), peripheral.DeviceName());
 }
 
 int CPeripherals::GetMappingForDevice(const CPeripheralBus &bus, const PeripheralType classType, int iVendorId, int iProductId) const
index 96a3b1f..a84afcc 100644 (file)
@@ -93,16 +93,16 @@ namespace PERIPHERALS
     /*!
      * @brief Called when a device has been added to a bus.
      * @param bus The bus the device was added to.
-     * @param strLocation The path of the fileitem.
+     * @param peripheral The peripheral that has been added.
      */
-    virtual void OnDeviceAdded(const CPeripheralBus &bus, const CStdString &strLocation);
+    virtual void OnDeviceAdded(const CPeripheralBus &bus, const CPeripheral &peripheral);
 
     /*!
      * @brief Called when a device has been deleted from a bus.
      * @param bus The bus from which the device removed.
-     * @param strLocation The path of the fileitem.
+     * @param peripheral The peripheral that has been removed.
      */
-    virtual void OnDeviceDeleted(const CPeripheralBus &bus, const CStdString &strLocation);
+    virtual void OnDeviceDeleted(const CPeripheralBus &bus, const CPeripheral &peripheral);
 
     /*!
      * @brief Creates a new instance of a peripheral.
index 9adff51..433a9d2 100644 (file)
@@ -147,7 +147,7 @@ void CPeripheralBus::UnregisterRemovedDevices(const PeripheralScanResults &resul
       m_peripherals.erase(m_peripherals.begin() + iDevicePtr);
       lock.Leave();
 
-      m_manager->OnDeviceDeleted(*this, peripheral->FileLocation());
+      m_manager->OnDeviceDeleted(*this, *peripheral);
       delete peripheral;
     }
   }
@@ -282,7 +282,7 @@ void CPeripheralBus::Register(CPeripheral *peripheral)
     CLog::Log(LOGNOTICE, "%s - new %s device registered on %s->%s: %s (%s:%s)", __FUNCTION__, PeripheralTypeTranslator::TypeToString(peripheral->Type()), PeripheralTypeTranslator::BusTypeToString(m_type), peripheral->Location().c_str(), peripheral->DeviceName().c_str(), peripheral->VendorIdAsString(), peripheral->ProductIdAsString());
     lock.Leave();
 
-    m_manager->OnDeviceAdded(*this, peripheral->FileLocation());
+    m_manager->OnDeviceAdded(*this, *peripheral);
   }
 }
 
index f8972d2..6e57e04 100644 (file)
@@ -310,13 +310,11 @@ void CPeripheralCecAdapter::ProcessNextCommand(void)
     case CEC_OPCODE_STANDBY:
       /* a device was put in standby mode */
       CLog::Log(LOGDEBUG, "%s - device %d was put in standby mode", __FUNCTION__, command.initiator);
-      if (command.initiator == CECDEVICE_TV && GetSettingBool("standby_pc_on_tv_standby"))
+      if (command.initiator == CECDEVICE_TV && GetSettingBool("standby_pc_on_tv_standby") &&
+          (!m_screensaverLastActivated.IsValid() || CDateTime::GetCurrentDateTime() - m_screensaverLastActivated > CDateTimeSpan(0, 0, 0, SCREENSAVER_TIMEOUT)))
       {
-        if (!m_screensaverLastActivated.IsValid() || CDateTime::GetCurrentDateTime() - m_screensaverLastActivated > CDateTimeSpan(0, 0, 0, SCREENSAVER_TIMEOUT))
-        {
-          m_bStarted = false;
-          g_application.getApplicationMessenger().Suspend();
-        }
+        m_bStarted = false;
+        g_application.getApplicationMessenger().Suspend();
       }
       break;
     default: