diff options
author | Elliott Hughes <enh@google.com> | 2015-02-04 01:49:41 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-02-04 01:49:42 +0000 |
commit | ff50e75d69b5cee253c213f91999e8f6f6129c58 (patch) | |
tree | 588f17752d3b224ba45d5543265ad07fa025d63e | |
parent | 481b0546db69274145ee129d19bb03cce4763c6f (diff) | |
parent | df3459935a4c12744a9a78812157890b60ccb77d (diff) | |
download | bluedroid-ff50e75d69b5cee253c213f91999e8f6f6129c58.tar.gz |
Merge "Fix pthread_t confusion."
-rw-r--r-- | btif/include/btif_hh.h | 3 | ||||
-rw-r--r-- | btif/src/btif_sock_thread.c | 31 |
2 files changed, 16 insertions, 18 deletions
diff --git a/btif/include/btif_hh.h b/btif/include/btif_hh.h index 7edba74..dc34d65 100644 --- a/btif/include/btif_hh.h +++ b/btif/include/btif_hh.h @@ -21,6 +21,7 @@ #include <hardware/bluetooth.h> #include <hardware/bt_hh.h> +#include <pthread.h> #include <stdint.h> #include "bta_hh_api.h" #include "btu.h" @@ -63,7 +64,7 @@ typedef struct UINT8 sub_class; UINT8 app_id; int fd; - UINT32 hh_poll_thread_id; + pthread_t hh_poll_thread_id; UINT8 hh_keep_polling; BOOLEAN vup_timer_active; TIMER_LIST_ENT vup_timer; diff --git a/btif/src/btif_sock_thread.c b/btif/src/btif_sock_thread.c index 71cf5db..6ae45bd 100644 --- a/btif/src/btif_sock_thread.c +++ b/btif/src/btif_sock_thread.c @@ -95,7 +95,7 @@ typedef struct { int poll_count; poll_slot_t ps[MAX_POLL]; int psi[MAX_POLL]; //index of poll slot - volatile pid_t thread_id; + volatile pthread_t thread_id; btsock_signaled_cb callback; btsock_cmd_cb cmd_callback; int used; @@ -111,18 +111,13 @@ static inline void add_poll(int h, int fd, int type, int flags, uint32_t user_id static pthread_mutex_t thread_slot_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; -static inline pthread_t create_thread(void *(*start_routine)(void *), void * arg) +static inline int create_thread(void *(*start_routine)(void *), void * arg, + pthread_t * thread_id) { pthread_attr_t thread_attr; pthread_attr_init(&thread_attr); pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE); - pthread_t thread_id = -1; - if( pthread_create(&thread_id, &thread_attr, start_routine, arg)!=0 ) - { - APPL_TRACE_ERROR("pthread_create : %s", strerror(errno)); - return -1; - } - return thread_id; + return pthread_create(thread_id, &thread_attr, start_routine, arg); } static void init_poll(int cmd_fd); static int alloc_thread_slot() @@ -180,17 +175,19 @@ int btsock_thread_create(btsock_signaled_cb callback, btsock_cmd_cb cmd_callback if(h >= 0) { init_poll(h); - if((ts[h].thread_id = create_thread(sock_poll_thread, (void*)(uintptr_t)h)) != -1) - { - APPL_TRACE_DEBUG("h:%d, thread id:%d", h, ts[h].thread_id); - ts[h].callback = callback; - ts[h].cmd_callback = cmd_callback; - } - else + pthread_t thread; + int status = create_thread(sock_poll_thread, (void*)(uintptr_t)h, &thread); + if (status) { + APPL_TRACE_ERROR("create_thread failed: %s", strerror(status)); free_thread_slot(h); - h = -1; + return -1; } + + ts[h].thread_id = thread; + APPL_TRACE_DEBUG("h:%d, thread id:%d", h, ts[h].thread_id); + ts[h].callback = callback; + ts[h].cmd_callback = cmd_callback; } return h; } |