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

Commit 135bb2c1 authored by Chris Manton's avatar Chris Manton
Browse files

Eliminate userial thread race condition

The userial thread MUST be torn down
BEFORE the hci worker thread
as the userial thread passes work to
the hci worker thread.

bug: 16708951
bug: 17008713

Change-Id: Ic744a06b81e7bba5f4d16707a7482a6b9ef437d1
parent 6fe74b8c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ bool userial_init(void);
// returns false if there was an error.
bool userial_open(userial_port_t port);
void userial_close(void);
void userial_close_reader(void);

// Reads a maximum of |len| bytes from the serial port into |p_buffer|.
// This function returns the number of bytes actually read, which may be
+4 −1
Original line number Diff line number Diff line
@@ -465,9 +465,11 @@ static void cleanup(void)
        if (fwcfg_acked)
        {
            epilog_wait_timer();
            // Stop reading thread
            userial_close_reader();

            thread_post(hc_cb.worker_thread, event_epilog, NULL);
        }

        thread_free(hc_cb.worker_thread);

        pthread_mutex_lock(&hc_cb.worker_thread_lock);
@@ -480,6 +482,7 @@ static void cleanup(void)
            hc_cb.epilog_timer_created = false;
        }
    }
    BTHCDBG("%s Finalizing cleanup\n", __func__);

    lpm_cleanup();
    userial_close();
+13 −0
Original line number Diff line number Diff line
@@ -374,6 +374,19 @@ uint16_t userial_write(uint16_t msg_id, const uint8_t *p_data, uint16_t len) {
    return total;
}

void userial_close_reader(void) {
    // Join the reader thread if it is still running.
    if (userial_running) {
        send_event(USERIAL_RX_EXIT);
        int result = pthread_join(userial_cb.read_thread, NULL);
        USERIALDBG("%s Joined userial reader thread: %d", __func__, result);
        if (result)
            ALOGE("%s failed to join reader thread: %d", __func__, result);
        return;
    }
    ALOGW("%s Already closed userial reader thread", __func__);
}

void userial_close(void) {
    assert(bt_hc_cbacks != NULL);