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

Commit 2f65d957 authored by Luke Zhang's avatar Luke Zhang Committed by Hemant Gupta
Browse files

Prevent deadlock between the Tx and Rx threads in HCI layer

Problem: Deadlock between HCI layer's Tx and Rx threads.

Cause: In HCI layer, both Tx and Rx tried to acquire
commands_pending_response_mutex simultaneously.
Since there may be a handshake between Tx and Rx
in the BT Transport layer, so it caused a deadlock between
HCI layer's Tx and Rx threads.

Fix: Fixed it by decreasing the scope of this mutex in Tx thread

Test: Simulated the deadlock sitaution and ensured RX thread is returned when TX is busy in binder.

Bug: 68305277
Change-Id: I0a2434ec24918b039a6993d57e68ac7495e31cbe
parent 88258d17
Loading
Loading
Loading
Loading
+6 −5
Original line number Original line Diff line number Diff line
@@ -394,11 +394,12 @@ static void enqueue_command(waiting_command_t* wait_entry) {
}
}


static void event_command_ready(waiting_command_t* wait_entry) {
static void event_command_ready(waiting_command_t* wait_entry) {
  {
    /// Move it to the list of commands awaiting response
    /// Move it to the list of commands awaiting response
    std::lock_guard<std::recursive_mutex> lock(commands_pending_response_mutex);
    std::lock_guard<std::recursive_mutex> lock(commands_pending_response_mutex);
    wait_entry->timestamp = std::chrono::steady_clock::now();
    wait_entry->timestamp = std::chrono::steady_clock::now();
    list_append(commands_pending_response, wait_entry);
    list_append(commands_pending_response, wait_entry);

  }
  // Send it off
  // Send it off
  packet_fragmenter->fragment_and_dispatch(wait_entry->command);
  packet_fragmenter->fragment_and_dispatch(wait_entry->command);