From: Sharvil Nanavati Date: Thu, 24 Jul 2014 21:24:27 +0000 (-0700) Subject: Expose thread's reactor so we can register new fds with it. X-Git-Tag: android-x86-7.1-r1~1277^2~383 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=9d461af487359872d8abcfa23a0f8747f401a88f;p=android-x86%2Fsystem-bt.git Expose thread's reactor so we can register new fds with it. This change allows a thread's reactor loop to manage additional file descriptors, e.g. sockets and queues, entirely within that thread's context. --- diff --git a/osi/include/thread.h b/osi/include/thread.h index c78c5e36a..ea92f524f 100644 --- a/osi/include/thread.h +++ b/osi/include/thread.h @@ -20,6 +20,7 @@ #define THREAD_NAME_MAX 16 +typedef struct reactor_t reactor_t; typedef struct thread_t thread_t; typedef void (*thread_fn)(void *context); @@ -46,5 +47,9 @@ bool thread_post(thread_t *thread, thread_fn func, void *context); // |thread| may not be NULL. void thread_stop(thread_t *thread); +// Returns a reactor owned by this thread. The reactor must not be freed by the +// caller. The returned reactor will not be NULL. |thread| may not be NULL. +reactor_t *thread_get_reactor(const thread_t *thread); + // Returns the name of the given |thread|. |thread| may not be NULL. const char *thread_name(const thread_t *thread); diff --git a/osi/src/thread.c b/osi/src/thread.c index cb644d35b..1c6995060 100644 --- a/osi/src/thread.c +++ b/osi/src/thread.c @@ -132,6 +132,11 @@ void thread_stop(thread_t *thread) { reactor_stop(thread->reactor); } +reactor_t *thread_get_reactor(const thread_t *thread) { + assert(thread != NULL); + return thread->reactor; +} + const char *thread_name(const thread_t *thread) { assert(thread != NULL); return thread->name;