зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1015826 - Use Atomic to ensure thread-safe, r=tzimmermann
This commit is contained in:
Родитель
5e386daa49
Коммит
2c49c88962
|
@ -46,26 +46,28 @@ using namespace mozilla;
|
|||
using namespace mozilla::ipc;
|
||||
USING_BLUETOOTH_NAMESPACE
|
||||
|
||||
// TODO: Non-thread safe variables
|
||||
static bluetooth_device_t* sBtDevice;
|
||||
static const bt_interface_t* sBtInterface;
|
||||
static bool sAdapterDiscoverable = false;
|
||||
// TODO: Non thread-safe static variables
|
||||
static nsString sAdapterBdAddress;
|
||||
static nsString sAdapterBdName;
|
||||
static uint32_t sAdapterDiscoverableTimeout;
|
||||
static InfallibleTArray<nsString> sAdapterBondedAddressArray;
|
||||
static InfallibleTArray<BluetoothNamedValue> sRemoteDevicesPack;
|
||||
static nsTArray<nsRefPtr<BluetoothProfileController> > sControllerArray;
|
||||
static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sBondingRunnableArray;
|
||||
static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sGetDeviceRunnableArray;
|
||||
static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sUnbondingRunnableArray;
|
||||
static nsTArray<int> sRequestedDeviceCountArray;
|
||||
|
||||
// Static variables below should only be used on *main thread*
|
||||
static const bt_interface_t* sBtInterface;
|
||||
static nsTArray<nsRefPtr<BluetoothProfileController> > sControllerArray;
|
||||
static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sSetPropertyRunnableArray;
|
||||
|
||||
// Static variables below should only be used on *callback thread*
|
||||
|
||||
|
||||
// Atomic static variables
|
||||
static Atomic<bool> sAdapterDiscoverable(false);
|
||||
static Atomic<uint32_t> sAdapterDiscoverableTimeout(0);
|
||||
|
||||
/**
|
||||
* Classes only used in this file
|
||||
*/
|
||||
|
@ -690,15 +692,17 @@ EnsureBluetoothHalLoad()
|
|||
{
|
||||
hw_module_t* module;
|
||||
hw_device_t* device;
|
||||
|
||||
int err = hw_get_module(BT_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
|
||||
if (err != 0) {
|
||||
BT_LOGR("Error: %s", strerror(err));
|
||||
return false;
|
||||
}
|
||||
module->methods->open(module, BT_HARDWARE_MODULE_ID, &device);
|
||||
sBtDevice = (bluetooth_device_t *)device;
|
||||
NS_ENSURE_TRUE(sBtDevice, false);
|
||||
sBtInterface = sBtDevice->get_bluetooth_interface();
|
||||
bluetooth_device_t* btDevice = (bluetooth_device_t *)device;
|
||||
NS_ENSURE_TRUE(btDevice, false);
|
||||
|
||||
sBtInterface = btDevice->get_bluetooth_interface();
|
||||
NS_ENSURE_TRUE(sBtInterface, false);
|
||||
|
||||
return true;
|
||||
|
@ -834,6 +838,11 @@ BluetoothServiceBluedroid::GetDefaultAdapterPathInternal(
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// Since Atomic<*> is not acceptable for BT_APPEND_NAMED_VALUE(),
|
||||
// create another variable to store data.
|
||||
bool discoverable = sAdapterDiscoverable;
|
||||
uint32_t discoverableTimeout = sAdapterDiscoverableTimeout;
|
||||
|
||||
BluetoothValue v = InfallibleTArray<BluetoothNamedValue>();
|
||||
|
||||
BT_APPEND_NAMED_VALUE(v.get_ArrayOfBluetoothNamedValue(),
|
||||
|
@ -843,10 +852,10 @@ BluetoothServiceBluedroid::GetDefaultAdapterPathInternal(
|
|||
"Name", sAdapterBdName);
|
||||
|
||||
BT_APPEND_NAMED_VALUE(v.get_ArrayOfBluetoothNamedValue(),
|
||||
"Discoverable", sAdapterDiscoverable);
|
||||
"Discoverable", discoverable);
|
||||
|
||||
BT_APPEND_NAMED_VALUE(v.get_ArrayOfBluetoothNamedValue(),
|
||||
"DiscoverableTimeout", sAdapterDiscoverableTimeout);
|
||||
"DiscoverableTimeout", discoverableTimeout);
|
||||
|
||||
BT_APPEND_NAMED_VALUE(v.get_ArrayOfBluetoothNamedValue(),
|
||||
"Devices", sAdapterBondedAddressArray);
|
||||
|
|
Загрузка…
Ссылка в новой задаче