From 9d461af487359872d8abcfa23a0f8747f401a88f Mon Sep 17 00:00:00 2001 From: Sharvil Nanavati Date: Thu, 24 Jul 2014 14:24:27 -0700 Subject: [PATCH] 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. --- osi/include/thread.h | 5 +++++ osi/src/thread.c | 5 +++++ 2 files changed, 10 insertions(+) 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; -- 2.11.0