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

Commit e1dacfc1 authored by Josh Gao's avatar Josh Gao
Browse files

adb: kill adb_thread_{create, join, detach, exit}.

We have std::thread now, so we can delete this cruft.

Test: python test_device.py
Test: adb_test
Test: wine adb_test.exe
Test: /data/nativetest/adbd_test/adbd_test
Change-Id: Ie1c1792547b20dec45e2a62ce6515fcb981c3ef8
parent 46de1d7f
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -574,7 +574,7 @@ static void register_device(const char* dev_name, const char* dev_path,
    register_usb_transport(done_usb, serial.c_str(), dev_path, done_usb->writeable);
}

static void device_poll_thread(void*) {
static void device_poll_thread() {
    adb_thread_setname("device poll");
    D("Created device thread");
    while (true) {
@@ -593,8 +593,6 @@ void usb_init() {
    actions.sa_handler = [](int) {};
    sigaction(SIGALRM, &actions, nullptr);

    if (!adb_thread_create(device_poll_thread, nullptr)) {
        fatal_errno("cannot create device_poll thread");
    }
    std::thread(device_poll_thread).detach();
}
} // namespace native
+2 −4
Original line number Diff line number Diff line
@@ -405,7 +405,7 @@ err_get_num_ep:

std::mutex& operate_device_lock = *new std::mutex();

static void RunLoopThread(void* unused) {
static void RunLoopThread() {
    adb_thread_setname("RunLoop");

    VLOG(USB) << "RunLoopThread started";
@@ -436,9 +436,7 @@ void usb_init() {

        usb_inited_flag = false;

        if (!adb_thread_create(RunLoopThread, nullptr)) {
            fatal_errno("cannot create RunLoop thread");
        }
        std::thread(RunLoopThread).detach();

        // Wait for initialization to finish
        while (!usb_inited_flag) {
+5 −9
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ static void kick_devices();

/// Entry point for thread that polls (every second) for new usb interfaces.
/// This routine calls find_devices in infinite loop.
static void device_poll_thread(void*);
static void device_poll_thread();

/// Initializes this module
void usb_init();
@@ -174,7 +174,7 @@ int register_new_device(usb_handle* handle) {
  return 1;
}

void device_poll_thread(void*) {
void device_poll_thread() {
  adb_thread_setname("Device Poll");
  D("Created device thread");

@@ -203,7 +203,7 @@ static LRESULT CALLBACK _power_window_proc(HWND hwnd, UINT uMsg, WPARAM wParam,
  return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}

static void _power_notification_thread(void*) {
static void _power_notification_thread() {
  // This uses a thread with its own window message pump to get power
  // notifications. If adb runs from a non-interactive service account, this
  // might not work (not sure). If that happens to not work, we could use
@@ -258,12 +258,8 @@ static void _power_notification_thread(void*) {
}

void usb_init() {
  if (!adb_thread_create(device_poll_thread, nullptr)) {
    fatal_errno("cannot create device poll thread");
  }
  if (!adb_thread_create(_power_notification_thread, nullptr)) {
    fatal_errno("cannot create power notification thread");
  }
  std::thread(device_poll_thread).detach();
  std::thread(_power_notification_thread).detach();
}

usb_handle* do_usb_open(const wchar_t* interface_name) {
+2 −7
Original line number Diff line number Diff line
@@ -663,13 +663,8 @@ static int RemoteShell(bool use_shell_protocol, const std::string& type_arg,
#endif

    // TODO: combine read_and_dump with stdin_read_thread to make life simpler?
    int exit_code = 1;
    if (!adb_thread_create(stdin_read_thread_loop, args)) {
        PLOG(ERROR) << "error starting stdin read thread";
        delete args;
    } else {
        exit_code = read_and_dump(fd, use_shell_protocol);
    }
    std::thread(stdin_read_thread_loop, args).detach();
    int exit_code = read_and_dump(fd, use_shell_protocol);

    // TODO: properly exit stdin_read_thread_loop and close |fd|.

+6 −4
Original line number Diff line number Diff line
@@ -17,12 +17,14 @@
#include "adb_mdns.h"
#include "sysdeps.h"

#include <chrono>
#include <dns_sd.h>
#include <endian.h>
#include <mutex>
#include <unistd.h>

#include <chrono>
#include <mutex>
#include <thread>

#include <android-base/logging.h>
#include <android-base/properties.h>

@@ -58,7 +60,7 @@ static void mdns_callback(DNSServiceRef /*ref*/,
    }
}

static void setup_mdns_thread(void* /* unused */) {
static void setup_mdns_thread() {
    start_mdns();
    std::lock_guard<std::mutex> lock(mdns_lock);

@@ -88,7 +90,7 @@ static void teardown_mdns() {

void setup_mdns(int port_in) {
    port = port_in;
    adb_thread_create(setup_mdns_thread, nullptr, nullptr);
    std::thread(setup_mdns_thread).detach();

    // TODO: Make this more robust against a hard kill.
    atexit(teardown_mdns);
Loading