From 967e380ba88bf99bafe2922cf0a1fbf5f3d19192 Mon Sep 17 00:00:00 2001 From: Mark Michelson Date: Tue, 15 Jan 2013 21:09:55 +0000 Subject: [PATCH] Make the threadpool listener opaque. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379126 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- include/asterisk/threadpool.h | 16 ++-------------- main/threadpool.c | 19 +++++++++++++++++++ tests/test_threadpool.c | 12 ++++++------ 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/include/asterisk/threadpool.h b/include/asterisk/threadpool.h index f003ace1f1..51abc63c45 100644 --- a/include/asterisk/threadpool.h +++ b/include/asterisk/threadpool.h @@ -67,20 +67,6 @@ struct ast_threadpool_listener_callbacks { void (*shutdown)(struct ast_threadpool_listener *listener); }; -/*! - * \brief listener for a threadpool - * - * The listener is notified of changes in a threadpool. It can - * react by doing things like increasing the number of threads - * in the pool - */ -struct ast_threadpool_listener { - /*! Callbacks called by the threadpool */ - const struct ast_threadpool_listener_callbacks *callbacks; - /*! User data for the listener */ - void *user_data; -}; - struct ast_threadpool_options { #define AST_THREADPOOL_OPTIONS_VERSION 1 /*! Version of thradpool options in use */ @@ -128,6 +114,8 @@ struct ast_threadpool_options { struct ast_threadpool_listener *ast_threadpool_listener_alloc( const struct ast_threadpool_listener_callbacks *callbacks, void *user_data); +void *ast_threadpool_listener_get_user_data(const struct ast_threadpool_listener *listener); + /*! * \brief Create a new threadpool * diff --git a/main/threadpool.c b/main/threadpool.c index 475a673fd1..e27b05345b 100644 --- a/main/threadpool.c +++ b/main/threadpool.c @@ -99,6 +99,20 @@ struct ast_threadpool { struct ast_threadpool_options options; }; +/*! + * \brief listener for a threadpool + * + * The listener is notified of changes in a threadpool. It can + * react by doing things like increasing the number of threads + * in the pool + */ +struct ast_threadpool_listener { + /*! Callbacks called by the threadpool */ + const struct ast_threadpool_listener_callbacks *callbacks; + /*! User data for the listener */ + void *user_data; +}; + /*! * \brief states for worker threads */ @@ -823,6 +837,11 @@ struct ast_threadpool_listener *ast_threadpool_listener_alloc( return listener; } +void *ast_threadpool_listener_get_user_data(const struct ast_threadpool_listener *listener) +{ + return listener->user_data; +} + struct pool_options_pair { struct ast_threadpool *pool; struct ast_threadpool_options options; diff --git a/tests/test_threadpool.c b/tests/test_threadpool.c index 1143056c38..4e04411b81 100644 --- a/tests/test_threadpool.c +++ b/tests/test_threadpool.c @@ -65,7 +65,7 @@ static void test_state_changed(struct ast_threadpool *pool, int active_threads, int idle_threads) { - struct test_listener_data *tld = listener->user_data; + struct test_listener_data *tld = ast_threadpool_listener_get_user_data(listener); SCOPED_MUTEX(lock, &tld->lock); tld->num_active = active_threads; tld->num_idle = idle_threads; @@ -77,7 +77,7 @@ static void test_task_pushed(struct ast_threadpool *pool, struct ast_threadpool_listener *listener, int was_empty) { - struct test_listener_data *tld = listener->user_data; + struct test_listener_data *tld = ast_threadpool_listener_get_user_data(listener); SCOPED_MUTEX(lock, &tld->lock); tld->task_pushed = 1; ++tld->num_tasks; @@ -88,7 +88,7 @@ static void test_task_pushed(struct ast_threadpool *pool, static void test_emptied(struct ast_threadpool *pool, struct ast_threadpool_listener *listener) { - struct test_listener_data *tld = listener->user_data; + struct test_listener_data *tld = ast_threadpool_listener_get_user_data(listener); SCOPED_MUTEX(lock, &tld->lock); tld->empty_notice = 1; ast_cond_signal(&tld->cond); @@ -96,7 +96,7 @@ static void test_emptied(struct ast_threadpool *pool, static void test_shutdown(struct ast_threadpool_listener *listener) { - struct test_listener_data *tld = listener->user_data; + struct test_listener_data *tld = ast_threadpool_listener_get_user_data(listener); ast_cond_destroy(&tld->cond); ast_mutex_destroy(&tld->lock); } @@ -163,7 +163,7 @@ static enum ast_test_result_state wait_until_thread_state(struct ast_test *test, static void wait_for_task_pushed(struct ast_threadpool_listener *listener) { - struct test_listener_data *tld = listener->user_data; + struct test_listener_data *tld = ast_threadpool_listener_get_user_data(listener); struct timeval start = ast_tvnow(); struct timespec end = { .tv_sec = start.tv_sec + 5, @@ -235,7 +235,7 @@ static enum ast_test_result_state listener_check( int num_idle, int empty_notice) { - struct test_listener_data *tld = listener->user_data; + struct test_listener_data *tld = ast_threadpool_listener_get_user_data(listener); enum ast_test_result_state res = AST_TEST_PASS; if (tld->task_pushed != task_pushed) {