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

Commit a3d96cfe authored by Josh Gao's avatar Josh Gao Committed by android-build-merger
Browse files

DO NOT MERGE: adb: use asocket\\'s close function when closing. am: 5218ad36

am: d7e24ec9

Change-Id: I9ca9e7e857de9e9679169cd7239f9e54a3d98dd2
parents 7f5da850 d7e24ec9
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -84,7 +84,9 @@ ifeq ($(USE_SYSDEPS_WIN32),)
	LOCAL_STATIC_LIBRARIES += libcutils
endif

ifneq ($(HOST_OS),windows)
  include $(BUILD_HOST_EXECUTABLE)
endif

$(call dist-for-goals,dist_files sdk,$(LOCAL_BUILT_MODULE))

+0 −1
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@
#ifndef ADB_MUTEX
#error ADB_MUTEX not defined when including this file
#endif
ADB_MUTEX(socket_list_lock)
ADB_MUTEX(transport_lock)
#if ADB_HOST
ADB_MUTEX(local_transports_lock)
+17 −23
Original line number Diff line number Diff line
@@ -20,15 +20,18 @@
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include <pthread.h>

#include "sysdeps.h"

#define  TRACE_TAG  TRACE_SOCKETS
#include "adb.h"

ADB_MUTEX_DEFINE( socket_list_lock );
#if defined(__BIONIC__)
#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER
#endif

static void local_socket_close_locked(asocket *s);
static pthread_mutex_t socket_list_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;

int sendfailmsg(int fd, const char *reason)
{
@@ -67,7 +70,7 @@ asocket *find_local_socket(unsigned local_id, unsigned peer_id)
    asocket *s;
    asocket *result = NULL;

    adb_mutex_lock(&socket_list_lock);
    pthread_mutex_lock(&socket_list_lock);
    for (s = local_socket_list.next; s != &local_socket_list; s = s->next) {
        if (s->id != local_id)
            continue;
@@ -76,7 +79,7 @@ asocket *find_local_socket(unsigned local_id, unsigned peer_id)
        }
        break;
    }
    adb_mutex_unlock(&socket_list_lock);
    pthread_mutex_unlock(&socket_list_lock);

    return result;
}
@@ -93,7 +96,7 @@ insert_local_socket(asocket* s, asocket* list)

void install_local_socket(asocket *s)
{
    adb_mutex_lock(&socket_list_lock);
    pthread_mutex_lock(&socket_list_lock);

    s->id = local_socket_next_id++;

@@ -103,7 +106,7 @@ void install_local_socket(asocket *s)

    insert_local_socket(s, &local_socket_list);

    adb_mutex_unlock(&socket_list_lock);
    pthread_mutex_unlock(&socket_list_lock);
}

void remove_socket(asocket *s)
@@ -126,15 +129,15 @@ void close_all_sockets(atransport *t)
        /* this is a little gross, but since s->close() *will* modify
        ** the list out from under you, your options are limited.
        */
    adb_mutex_lock(&socket_list_lock);
    pthread_mutex_lock(&socket_list_lock);
restart:
    for(s = local_socket_list.next; s != &local_socket_list; s = s->next){
        if(s->transport == t || (s->peer && s->peer->transport == t)) {
            local_socket_close_locked(s);
            s->close(s);
            goto restart;
        }
    }
    adb_mutex_unlock(&socket_list_lock);
    pthread_mutex_unlock(&socket_list_lock);
}

static int local_socket_enqueue(asocket *s, apacket *p)
@@ -198,13 +201,6 @@ static void local_socket_ready(asocket *s)
//    D("LS(%d): ready()\n", s->id);
}

static void local_socket_close(asocket *s)
{
    adb_mutex_lock(&socket_list_lock);
    local_socket_close_locked(s);
    adb_mutex_unlock(&socket_list_lock);
}

// be sure to hold the socket list lock when calling this
static void local_socket_destroy(asocket  *s)
{
@@ -234,8 +230,9 @@ static void local_socket_destroy(asocket *s)
}


static void local_socket_close_locked(asocket *s)
static void local_socket_close(asocket *s)
{
    pthread_mutex_lock(&socket_list_lock);
    D("entered. LS(%d) fd=%d\n", s->id, s->fd);
    if(s->peer) {
        D("LS(%d): closing peer. peer->id=%d peer->fd=%d\n",
@@ -247,12 +244,7 @@ static void local_socket_close_locked(asocket *s)
        if (s->peer->shutdown)
          s->peer->shutdown(s->peer);
        s->peer->peer = 0;
        // tweak to avoid deadlock
        if (s->peer->close == local_socket_close) {
            local_socket_close_locked(s->peer);
        } else {
        s->peer->close(s->peer);
        }
        s->peer = 0;
    }

@@ -263,6 +255,7 @@ static void local_socket_close_locked(asocket *s)
        int   id = s->id;
        local_socket_destroy(s);
        D("LS(%d): closed\n", id);
        pthread_mutex_unlock(&socket_list_lock);
        return;
    }

@@ -274,6 +267,7 @@ static void local_socket_close_locked(asocket *s)
    remove_socket(s);
    D("LS(%d): put on socket_closing_list fd=%d\n", s->id, s->fd);
    insert_local_socket(s, &local_socket_closing_list);
    pthread_mutex_unlock(&socket_list_lock);
}

static void local_socket_event_func(int fd, unsigned ev, void *_s)