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

Commit 19d3ec83 authored by Chris Manton's avatar Chris Manton Committed by Android Git Automerger
Browse files

am e11eda16: Protect hci library cleanup with mutex

* commit 'e11eda16':
  Protect hci library cleanup with mutex
parents 1d0e24cf e11eda16
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -74,6 +74,8 @@ void init_vnd_if(unsigned char *local_bdaddr);
bt_hc_callbacks_t *bt_hc_cbacks = NULL;
tHCI_IF *p_hci_if;
volatile bool fwcfg_acked;
// Cleanup state indication.
volatile bool has_cleaned_up = false;

/******************************************************************************
**  Local type definitions
@@ -325,6 +327,7 @@ static int init(const bt_hc_callbacks_t* p_cb, unsigned char *local_bdaddr)

    hc_cb.epilog_timer_created = false;
    fwcfg_acked = false;
    has_cleaned_up = false;

    pthread_mutex_init(&hc_cb.worker_thread_lock, NULL);

@@ -446,9 +449,15 @@ static int tx_hc_cmd(TRANSAC transac, char *p_buf, int len) {
  return BT_HC_STATUS_SUCCESS;
}

/** Closes the interface */
// Closes the interface.
// This routine is not thread safe.
static void cleanup(void)
{
    if (has_cleaned_up) {
        ALOGW("%s Already cleaned up for this session\n", __func__);
        return;
    }

    BTHCDBG("cleanup");

    if (hc_cb.worker_thread)
@@ -484,6 +493,7 @@ static void cleanup( void )

    fwcfg_acked = false;
    bt_hc_cbacks = NULL;
    has_cleaned_up = true;
}

static const bt_hc_interface_t bluetoothHCLibInterface = {
+18 −7
Original line number Diff line number Diff line
@@ -84,7 +84,6 @@ BOOLEAN hci_logging_enabled = FALSE; /* by default, turn hci log off */
BOOLEAN hci_logging_config = FALSE;    /* configured from bluetooth framework */
char hci_logfile[256] = HCI_LOGGING_FILENAME;


/*******************************************************************************
**  Static variables
*******************************************************************************/
@@ -92,6 +91,8 @@ static bt_hc_interface_t *bt_hc_if=NULL;
static const bt_hc_callbacks_t hc_callbacks;
static BOOLEAN lpm_enabled = FALSE;
static bt_preload_retry_cb_t preload_retry_cb;
// Lock to serialize cleanup requests from upper layer.
static pthread_mutex_t cleanup_lock;

/*******************************************************************************
**  Static functions
@@ -171,6 +172,9 @@ void bte_main_boot_entry(void)
    /* Initialize trace feature */
    BTTRC_TraceInit(MAX_TRACE_RAM_SIZE, &BTE_TraceLogBuf[0], BTTRC_METHOD_RAM);
#endif

    pthread_mutex_init(&cleanup_lock, NULL);

}

/******************************************************************************
@@ -184,6 +188,8 @@ void bte_main_boot_entry(void)
******************************************************************************/
void bte_main_shutdown()
{
    pthread_mutex_destroy(&cleanup_lock);

    GKI_shutdown();
}

@@ -325,12 +331,17 @@ static void bte_hci_disable(void)
{
    APPL_TRACE_DEBUG("%s", __FUNCTION__);

    if (bt_hc_if)
    {
    if (!bt_hc_if)
        return;

    // Cleanup is not thread safe and must be protected.
    pthread_mutex_lock(&cleanup_lock);

    if (hci_logging_enabled == TRUE ||  hci_logging_config == TRUE)
        bt_hc_if->logging(BT_HC_LOGGING_OFF, hci_logfile);
    bt_hc_if->cleanup();
    }

    pthread_mutex_unlock(&cleanup_lock);
}

/*******************************************************************************