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

Commit c9525ec3 authored by Siva Velusamy's avatar Siva Velusamy Committed by Gerrit Code Review
Browse files

Merge "adb: set thread names (linux & mac)"

parents 9f07f879 49ee7cf9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -670,10 +670,12 @@ static unsigned _redirect_pipe_thread(HANDLE h, DWORD nStdHandle) {
}

static unsigned __stdcall _redirect_stdout_thread(HANDLE h) {
    adb_thread_setname("stdout redirect");
    return _redirect_pipe_thread(h, STD_OUTPUT_HANDLE);
}

static unsigned __stdcall _redirect_stderr_thread(HANDLE h) {
    adb_thread_setname("stderr redirect");
    return _redirect_pipe_thread(h, STD_ERROR_HANDLE);
}

+2 −0
Original line number Diff line number Diff line
@@ -374,6 +374,8 @@ static void *stdin_read_thread(void *x)
    fdi = fds[1];
    free(fds);

    adb_thread_setname("stdin reader");

    while (true) {
        /* fdi is really the client's stdin, so use read, not adb_read here */
        D("stdin_read_thread(): pre unix_read(fdi=%d,...)\n", fdi);
+1 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ enum class SubprocessType {
void *service_bootstrap_func(void *x)
{
    stinfo* sti = reinterpret_cast<stinfo*>(x);
    adb_thread_setname(android::base::StringPrintf("service %d", sti->fd));
    sti->func(sti->fd, sti->cookie);
    free(sti);
    return 0;
+27 −1
Original line number Diff line number Diff line
@@ -111,6 +111,13 @@ static __inline__ bool adb_thread_create(adb_thread_func_t func, void* arg) {
    return (tid != static_cast<uintptr_t>(-1L));
}

static __inline__ int adb_thread_setname(const std::string& name) {
    // TODO: See https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx for how to set
    // the thread name in Windows. Unfortunately, it only works during debugging, but
    // our build process doesn't generate PDB files needed for debugging.
    return 0;
}

static __inline__  unsigned long adb_thread_id()
{
    return GetCurrentThreadId();
@@ -617,6 +624,25 @@ static __inline__ bool adb_thread_create(adb_thread_func_t start, void* arg) {
    return (errno == 0);
}

static __inline__ int adb_thread_setname(const std::string& name) {
#ifdef __APPLE__
    return pthread_setname_np(name.c_str());
#else
    const char *s = name.c_str();

    // pthread_setname_np fails rather than truncating long strings.
    const int max_task_comm_len = 16; // including the null terminator
    if (name.length() > (max_task_comm_len - 1)) {
        char buf[max_task_comm_len];
        strncpy(buf, name.c_str(), sizeof(buf) - 1);
        buf[sizeof(buf) - 1] = '\0';
        s = buf;
    }

    return pthread_setname_np(pthread_self(), s) ;
#endif
}

static __inline__  int  adb_socket_setbufsize(int fd, int  bufsize )
{
    int opt = bufsize;
+2 −0
Original line number Diff line number Diff line
@@ -193,6 +193,7 @@ static void *output_thread(void *_t)
    atransport *t = reinterpret_cast<atransport*>(_t);
    apacket *p;

    adb_thread_setname("to transport");
    D("%s: starting transport output thread on fd %d, SYNC online (%d)\n",
       t->serial, t->fd, t->sync_token + 1);
    p = get_apacket();
@@ -249,6 +250,7 @@ static void *input_thread(void *_t)
    apacket *p;
    int active = 0;

    adb_thread_setname("from transport");
    D("%s: starting transport input thread, reading from fd %d\n",
       t->serial, t->fd);

Loading