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

Commit b31a5f8c authored by Andre Eisenbach's avatar Andre Eisenbach Committed by Android Git Automerger
Browse files

am 7296187f: Merge "Eliminate userial thread race condition" into lmp-dev

* commit '7296187f':
  Eliminate userial thread race condition
parents 92651837 7296187f
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);