From e36fd9541b668ccaec651e480b5114b96c98bcf6 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Thu, 6 Mar 2014 12:43:35 +0100 Subject: [PATCH] Bug 978809: Remove sToggleBtMonitor from Bluedroid backend, r=echou When enabling or disabling Bluetooth, the Bluedroid backend waits on sToggleBtMonitor until a BT adapter has been activated. Once the monitor gets notified, the backend sends a ToggleBtAck runnable to the main thread. This patch removes sToggleBtMonitor from the Bluetooth Bluedroid backend. Instead of signalling the monitor's notification, the Bluedroid handler function sends the ToggleBtAck directly. --- .../bluedroid/BluetoothServiceBluedroid.cpp | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp index 5a7e770d8c0e..e7a95085d4b0 100644 --- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp +++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp @@ -55,7 +55,6 @@ static nsTArray > sGetDeviceRunnableArray; static nsTArray > sSetPropertyRunnableArray; static nsTArray > sUnbondingRunnableArray; static nsTArray sRequestedDeviceCountArray; -static StaticAutoPtr sToggleBtMonitor; /** * Classes only used in this file @@ -246,9 +245,11 @@ AdapterStateChangeCallback(bt_state_t aStatus) sIsBtEnabled = (aStatus == BT_STATE_ON); - { - MonitorAutoLock lock(*sToggleBtMonitor); - lock.Notify(); + nsRefPtr runnable = + new BluetoothService::ToggleBtAck(sIsBtEnabled); + if (NS_FAILED(NS_DispatchToMainThread(runnable))) { + BT_WARNING("Failed to dispatch to main thread!"); + return; } if (sIsBtEnabled && @@ -670,15 +671,17 @@ StartStopGonkBluetooth(bool aShouldEnable) if (sIsBtEnabled == aShouldEnable) { // Keep current enable status + nsRefPtr runnable = + new BluetoothService::ToggleBtAck(sIsBtEnabled); + if (NS_FAILED(NS_DispatchToMainThread(runnable))) { + BT_WARNING("Failed to dispatch to main thread!"); + } return NS_OK; } int ret = aShouldEnable ? sBtInterface->enable() : sBtInterface->disable(); NS_ENSURE_TRUE(ret == BT_STATUS_SUCCESS, NS_ERROR_FAILURE); - MonitorAutoLock lock(*sToggleBtMonitor); - lock.Wait(); - return NS_OK; } @@ -716,8 +719,6 @@ ReplyStatusError(BluetoothReplyRunnable* aBluetoothReplyRunnable, */ BluetoothServiceBluedroid::BluetoothServiceBluedroid() { - sToggleBtMonitor = new Monitor("BluetoothService.sToggleBtMonitor"); - if (!EnsureBluetoothHalLoad()) { BT_LOGR("Error! Failed to load bluedroid library."); return; @@ -731,7 +732,6 @@ BluetoothServiceBluedroid::BluetoothServiceBluedroid() BluetoothServiceBluedroid::~BluetoothServiceBluedroid() { - sToggleBtMonitor = nullptr; } nsresult @@ -741,18 +741,14 @@ BluetoothServiceBluedroid::StartInternal() nsresult ret = StartStopGonkBluetooth(true); if (NS_FAILED(ret)) { - nsCOMPtr ackTask = new BluetoothService::ToggleBtAck(false); - if (NS_FAILED(NS_DispatchToMainThread(ackTask))) { + nsRefPtr runnable = + new BluetoothService::ToggleBtAck(false); + if (NS_FAILED(NS_DispatchToMainThread(runnable))) { BT_WARNING("Failed to dispatch to main thread!"); } BT_LOGR("Error"); } - nsCOMPtr ackTask = new BluetoothService::ToggleBtAck(true); - if (NS_FAILED(NS_DispatchToMainThread(ackTask))) { - BT_WARNING("Failed to dispatch to main thread!"); - } - return ret; } @@ -763,18 +759,14 @@ BluetoothServiceBluedroid::StopInternal() nsresult ret = StartStopGonkBluetooth(false); if (NS_FAILED(ret)) { - nsCOMPtr ackTask = new BluetoothService::ToggleBtAck(true); - if (NS_FAILED(NS_DispatchToMainThread(ackTask))) { + nsRefPtr runnable = + new BluetoothService::ToggleBtAck(true); + if (NS_FAILED(NS_DispatchToMainThread(runnable))) { BT_WARNING("Failed to dispatch to main thread!"); } BT_LOGR("Error"); } - nsCOMPtr ackTask = new BluetoothService::ToggleBtAck(false); - if (NS_FAILED(NS_DispatchToMainThread(ackTask))) { - BT_WARNING("Failed to dispatch to main thread!"); - } - return ret; }