OSDN Git Service

Expose thread's reactor so we can register new fds with it.
authorSharvil Nanavati <sharvil@google.com>
Thu, 24 Jul 2014 21:24:27 +0000 (14:24 -0700)
committerAndre Eisenbach <eisenbach@google.com>
Mon, 16 Mar 2015 23:51:27 +0000 (16:51 -0700)
This change allows a thread's reactor loop to manage additional
file descriptors, e.g. sockets and queues, entirely within that
thread's context.

osi/include/thread.h
osi/src/thread.c

index c78c5e3..ea92f52 100644 (file)
@@ -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);
index cb644d3..1c69950 100644 (file)
@@ -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;