Merge "Simplify adb_thread_create."
This commit is contained in:
commit
89114c5000
9 changed files with 27 additions and 49 deletions
|
@ -403,7 +403,6 @@ static void *stdin_read_thread(void *x)
|
|||
}
|
||||
|
||||
static int interactive_shell() {
|
||||
adb_thread_t thr;
|
||||
int fdi;
|
||||
|
||||
std::string error;
|
||||
|
@ -424,7 +423,8 @@ static int interactive_shell() {
|
|||
fds[1] = fdi;
|
||||
|
||||
stdin_raw_init(fdi);
|
||||
adb_thread_create(&thr, stdin_read_thread, fds);
|
||||
|
||||
adb_thread_create(stdin_read_thread, fds);
|
||||
read_and_dump(fd);
|
||||
stdin_raw_restore(fdi);
|
||||
return 0;
|
||||
|
|
|
@ -210,8 +210,7 @@ static int create_service_thread(void (*func)(int, void *), void *cookie)
|
|||
sti->cookie = cookie;
|
||||
sti->fd = s[1];
|
||||
|
||||
adb_thread_t t;
|
||||
if (adb_thread_create(&t, service_bootstrap_func, sti)) {
|
||||
if (!adb_thread_create(service_bootstrap_func, sti)) {
|
||||
free(sti);
|
||||
adb_close(s[0]);
|
||||
adb_close(s[1]);
|
||||
|
@ -401,8 +400,7 @@ static int create_subproc_thread(const char *name, bool pty = false) {
|
|||
sti->cookie = (void*) (uintptr_t) pid;
|
||||
sti->fd = ret_fd;
|
||||
|
||||
adb_thread_t t;
|
||||
if (adb_thread_create(&t, service_bootstrap_func, sti)) {
|
||||
if (!adb_thread_create(service_bootstrap_func, sti)) {
|
||||
free(sti);
|
||||
adb_close(ret_fd);
|
||||
fprintf(stderr, "cannot create service thread\n");
|
||||
|
|
|
@ -79,19 +79,13 @@ static __inline__ void adb_mutex_unlock( adb_mutex_t* lock )
|
|||
LeaveCriticalSection( lock );
|
||||
}
|
||||
|
||||
typedef struct { unsigned tid; } adb_thread_t;
|
||||
|
||||
typedef void* (*adb_thread_func_t)(void* arg);
|
||||
|
||||
typedef void (*win_thread_func_t)(void* arg);
|
||||
|
||||
static __inline__ int adb_thread_create( adb_thread_t *thread, adb_thread_func_t func, void* arg)
|
||||
{
|
||||
thread->tid = _beginthread( (win_thread_func_t)func, 0, arg );
|
||||
if (thread->tid == (unsigned)-1L) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
static __inline__ bool adb_thread_create(adb_thread_func_t func, void* arg) {
|
||||
unsigned tid = _beginthread( (win_thread_func_t)func, 0, arg );
|
||||
return (tid != (unsigned)-1L);
|
||||
}
|
||||
|
||||
static __inline__ unsigned long adb_thread_id()
|
||||
|
@ -429,18 +423,16 @@ static __inline__ int adb_socket_accept(int serverfd, struct sockaddr* addr,
|
|||
#define unix_write adb_write
|
||||
#define unix_close adb_close
|
||||
|
||||
typedef pthread_t adb_thread_t;
|
||||
|
||||
typedef void* (*adb_thread_func_t)( void* arg );
|
||||
|
||||
static __inline__ int adb_thread_create( adb_thread_t *pthread, adb_thread_func_t start, void* arg )
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
static __inline__ bool adb_thread_create(adb_thread_func_t start, void* arg) {
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
|
||||
pthread_attr_init (&attr);
|
||||
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
|
||||
|
||||
return pthread_create( pthread, &attr, start, arg );
|
||||
pthread_t thread;
|
||||
errno = pthread_create(&thread, &attr, start, arg);
|
||||
return (errno == 0);
|
||||
}
|
||||
|
||||
static __inline__ int adb_socket_setbufsize( int fd, int bufsize )
|
||||
|
|
|
@ -530,8 +530,6 @@ transport_write_action(int fd, struct tmsg* m)
|
|||
static void transport_registration_func(int _fd, unsigned ev, void *data)
|
||||
{
|
||||
tmsg m;
|
||||
adb_thread_t output_thread_ptr;
|
||||
adb_thread_t input_thread_ptr;
|
||||
int s[2];
|
||||
atransport *t;
|
||||
|
||||
|
@ -600,11 +598,11 @@ static void transport_registration_func(int _fd, unsigned ev, void *data)
|
|||
|
||||
fdevent_set(&(t->transport_fde), FDE_READ);
|
||||
|
||||
if(adb_thread_create(&input_thread_ptr, input_thread, t)){
|
||||
if (!adb_thread_create(input_thread, t)) {
|
||||
fatal_errno("cannot create input thread");
|
||||
}
|
||||
|
||||
if(adb_thread_create(&output_thread_ptr, output_thread, t)){
|
||||
if (!adb_thread_create(output_thread, t)) {
|
||||
fatal_errno("cannot create output thread");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -234,9 +234,8 @@ static const char _ok_resp[] = "ok";
|
|||
if (fd < 0) {
|
||||
/* This could be an older version of the emulator, that doesn't
|
||||
* implement adb QEMUD service. Fall back to the old TCP way. */
|
||||
adb_thread_t thr;
|
||||
D("adb service is not available. Falling back to TCP socket.\n");
|
||||
adb_thread_create(&thr, server_socket_thread, arg);
|
||||
adb_thread_create(server_socket_thread, arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -279,7 +278,6 @@ static const char _ok_resp[] = "ok";
|
|||
|
||||
void local_init(int port)
|
||||
{
|
||||
adb_thread_t thr;
|
||||
void* (*func)(void *);
|
||||
|
||||
if(HOST) {
|
||||
|
@ -304,9 +302,8 @@ void local_init(int port)
|
|||
|
||||
D("transport: local %s init\n", HOST ? "client" : "server");
|
||||
|
||||
if(adb_thread_create(&thr, func, (void *) (uintptr_t) port)) {
|
||||
fatal_errno("cannot create local socket %s thread",
|
||||
HOST ? "client" : "server");
|
||||
if (!adb_thread_create(func, (void *) (uintptr_t) port)) {
|
||||
fatal_errno("cannot create local socket %s thread", HOST ? "client" : "server");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -668,7 +668,6 @@ static void sigalrm_handler(int signo)
|
|||
|
||||
void usb_init()
|
||||
{
|
||||
adb_thread_t tid;
|
||||
struct sigaction actions;
|
||||
|
||||
memset(&actions, 0, sizeof(actions));
|
||||
|
@ -677,7 +676,7 @@ void usb_init()
|
|||
actions.sa_handler = sigalrm_handler;
|
||||
sigaction(SIGALRM,& actions, NULL);
|
||||
|
||||
if(adb_thread_create(&tid, device_poll_thread, NULL)){
|
||||
if (!adb_thread_create(device_poll_thread, nullptr)) {
|
||||
fatal_errno("cannot create input thread");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -264,8 +264,7 @@ static void usb_adb_init()
|
|||
}
|
||||
|
||||
D("[ usb_init - starting thread ]\n");
|
||||
adb_thread_t tid;
|
||||
if(adb_thread_create(&tid, usb_adb_open_thread, h)){
|
||||
if (!adb_thread_create(usb_adb_open_thread, h)) {
|
||||
fatal_errno("cannot create usb thread");
|
||||
}
|
||||
}
|
||||
|
@ -483,8 +482,7 @@ static void usb_ffs_init()
|
|||
adb_mutex_init(&h->lock, 0);
|
||||
|
||||
D("[ usb_init - starting thread ]\n");
|
||||
adb_thread_t tid;
|
||||
if (adb_thread_create(&tid, usb_ffs_open_thread, h)){
|
||||
if (!adb_thread_create(usb_ffs_open_thread, h)) {
|
||||
fatal_errno("[ cannot create usb thread ]\n");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -398,22 +398,20 @@ void* RunLoopThread(void* unused)
|
|||
IONotificationPortDestroy(notificationPort);
|
||||
|
||||
DBG("RunLoopThread done\n");
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static int initialized = 0;
|
||||
void usb_init()
|
||||
{
|
||||
void usb_init() {
|
||||
if (!initialized)
|
||||
{
|
||||
adb_thread_t tid;
|
||||
|
||||
adb_mutex_init(&start_lock, NULL);
|
||||
adb_cond_init(&start_cond, NULL);
|
||||
|
||||
if(adb_thread_create(&tid, RunLoopThread, NULL))
|
||||
if (!adb_thread_create(RunLoopThread, nullptr)) {
|
||||
fatal_errno("cannot create input thread");
|
||||
}
|
||||
|
||||
// Wait for initialization to finish
|
||||
adb_mutex_lock(&start_lock);
|
||||
|
|
|
@ -181,9 +181,7 @@ void* device_poll_thread(void* unused) {
|
|||
}
|
||||
|
||||
void usb_init() {
|
||||
adb_thread_t tid;
|
||||
|
||||
if(adb_thread_create(&tid, device_poll_thread, NULL)) {
|
||||
if (!adb_thread_create(device_poll_thread, nullptr)) {
|
||||
fatal_errno("cannot create input thread");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue