[asterisk-commits] mmichelson: branch mmichelson/threadpool r379126 - in /team/mmichelson/thread...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 15 15:09:59 CST 2013


Author: mmichelson
Date: Tue Jan 15 15:09:55 2013
New Revision: 379126

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379126
Log:
Make the threadpool listener opaque.


Modified:
    team/mmichelson/threadpool/include/asterisk/threadpool.h
    team/mmichelson/threadpool/main/threadpool.c
    team/mmichelson/threadpool/tests/test_threadpool.c

Modified: team/mmichelson/threadpool/include/asterisk/threadpool.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/include/asterisk/threadpool.h?view=diff&rev=379126&r1=379125&r2=379126
==============================================================================
--- team/mmichelson/threadpool/include/asterisk/threadpool.h (original)
+++ team/mmichelson/threadpool/include/asterisk/threadpool.h Tue Jan 15 15:09:55 2013
@@ -67,20 +67,6 @@
 	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 */
@@ -127,6 +113,8 @@
  */
 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

Modified: team/mmichelson/threadpool/main/threadpool.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/main/threadpool.c?view=diff&rev=379126&r1=379125&r2=379126
==============================================================================
--- team/mmichelson/threadpool/main/threadpool.c (original)
+++ team/mmichelson/threadpool/main/threadpool.c Tue Jan 15 15:09:55 2013
@@ -100,6 +100,20 @@
 };
 
 /*!
+ * \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
  */
 enum worker_state {
@@ -823,6 +837,11 @@
 	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;

Modified: team/mmichelson/threadpool/tests/test_threadpool.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/tests/test_threadpool.c?view=diff&rev=379126&r1=379125&r2=379126
==============================================================================
--- team/mmichelson/threadpool/tests/test_threadpool.c (original)
+++ team/mmichelson/threadpool/tests/test_threadpool.c Tue Jan 15 15:09:55 2013
@@ -65,7 +65,7 @@
 		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 @@
 		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_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_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 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 @@
 		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) {




More information about the asterisk-commits mailing list