Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 019d049b authored by Pavlin Radoslavov's avatar Pavlin Radoslavov Committed by android-build-merger
Browse files

Fix a race condition during HCI module shutdown

am: 051b9f4e

Change-Id: I2116b3d5e0c992a4fbd35745ee5c9b3f14fdb1a9
parents c4bb0fc0 051b9f4e
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -224,10 +224,13 @@ static future_t* hci_module_shut_down() {
  LOG_INFO(LOG_TAG, "%s", __func__);

  // Free the timers
  {
    std::lock_guard<std::recursive_mutex> lock(commands_pending_response_mutex);
    alarm_free(command_response_timer);
    command_response_timer = NULL;
    alarm_free(startup_timer);
    startup_timer = NULL;
  }

  // Stop the thread to prevent Send() calls.
  if (thread) {
@@ -533,6 +536,8 @@ static waiting_command_t* get_waiting_command(command_opcode_t opcode) {

static void update_command_response_timer(void) {
  std::lock_guard<std::recursive_mutex> lock(commands_pending_response_mutex);

  if (command_response_timer == NULL) return;
  if (list_is_empty(commands_pending_response)) {
    alarm_cancel(command_response_timer);
  } else {
+2 −0
Original line number Diff line number Diff line
@@ -228,6 +228,8 @@ class BluetoothInterfaceImpl : public BluetoothInterface {

  const bt_interface_t* GetHALInterface() const override { return hal_iface_; }

  bt_callbacks_t* GetHALCallbacks() const override { return &bt_callbacks; }

  const bluetooth_device_t* GetHALAdapter() const override {
    return hal_adapter_;
  }
+3 −0
Original line number Diff line number Diff line
@@ -108,6 +108,9 @@ class BluetoothInterface {
  // us. The behavior is undefined if "init" is called directly by upper layers.
  virtual const bt_interface_t* GetHALInterface() const = 0;

  // Returns the HAL callbacks that have been initialized previously.
  virtual bt_callbacks_t* GetHALCallbacks() const = 0;

  // The HAL module pointer that represents the underlying Bluetooth adapter.
  // This is implemented in and provided by the shared Bluetooth library, so
  // this isn't owned by us.
+4 −0
Original line number Diff line number Diff line
@@ -152,6 +152,10 @@ const bt_interface_t* FakeBluetoothInterface::GetHALInterface() const {
  return &fake_bt_iface;
}

bt_callbacks_t* FakeBluetoothInterface::GetHALCallbacks() const {
  return nullptr;
}

const bluetooth_device_t* FakeBluetoothInterface::GetHALAdapter() const {
  // TODO(armansito): Do something meaningful here to simulate test behavior.
  return nullptr;
+1 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ class FakeBluetoothInterface : public BluetoothInterface {
  void AddObserver(Observer* observer) override;
  void RemoveObserver(Observer* observer) override;
  const bt_interface_t* GetHALInterface() const override;
  bt_callbacks_t* GetHALCallbacks() const override;
  const bluetooth_device_t* GetHALAdapter() const override;

 private:
Loading