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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Nov 15 22:33:56 CST 2012


Author: mmichelson
Date: Thu Nov 15 22:33:53 2012
New Revision: 376381

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=376381
Log:
Add a shutdown callback to taskprocessor listeners.

This helps account for the fact that it is unknown just
how many references may exist for a given taskprocessor
listener, so simply unreffing it from the taskprocessor
shutdown function is not enough to convey the gravity
of the situation.

By putting in a shutdown callback, it now becomes clear
to the listener not to try to do any further operations
on the taskprocessor.


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

Modified: team/mmichelson/threadpool/include/asterisk/taskprocessor.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/include/asterisk/taskprocessor.h?view=diff&rev=376381&r1=376380&r2=376381
==============================================================================
--- team/mmichelson/threadpool/include/asterisk/taskprocessor.h (original)
+++ team/mmichelson/threadpool/include/asterisk/taskprocessor.h Thu Nov 15 22:33:53 2012
@@ -86,6 +86,18 @@
 	 * \param listener The listener
 	 */
 	void (*emptied)(struct ast_taskprocessor_listener *listener);
+	/*!
+	 * \brief Indicates the taskprocessor wishes to die.
+	 *
+	 * All operations on the task processor must to be stopped in
+	 * this callback.
+	 *
+	 * After this callback returns, it is NOT safe to operate on the
+	 * listener's reference to the taskprocessor.
+	 *
+	 * \param listener The listener
+	 */
+	void (*shutdown)(struct ast_taskprocessor_listener *listener);
 	/*! 
 	 * \brief Destroy the listener's private data
 	 *

Modified: team/mmichelson/threadpool/main/taskprocessor.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/main/taskprocessor.c?view=diff&rev=376381&r1=376380&r2=376381
==============================================================================
--- team/mmichelson/threadpool/main/taskprocessor.c (original)
+++ team/mmichelson/threadpool/main/taskprocessor.c Thu Nov 15 22:33:53 2012
@@ -136,7 +136,11 @@
 	struct ast_taskprocessor_listener *listener = obj;
 
 	listener->callbacks->destroy(listener->private_data);
-
+}
+
+static void listener_shutdown(struct ast_taskprocessor_listener *listener)
+{
+	listener->callbacks->shutdown(listener);
 	ao2_ref(listener->tps, -1);
 	listener->tps = NULL;
 }
@@ -184,13 +188,17 @@
 	return pvt;
 }
 
-static void default_listener_destroy(void *obj)
-{
-	struct default_taskprocessor_listener_pvt *pvt = obj;
-
+static void default_listener_shutdown(struct ast_taskprocessor_listener *listener)
+{
+	struct default_taskprocessor_listener_pvt *pvt = listener->private_data;
 	default_tps_wake_up(pvt, 1);
 	pthread_join(pvt->poll_thread, NULL);
 	pvt->poll_thread = AST_PTHREADT_NULL;
+}
+
+static void default_listener_destroy(void *obj)
+{
+	struct default_taskprocessor_listener_pvt *pvt = obj;
 	ast_mutex_destroy(&pvt->lock);
 	ast_cond_destroy(&pvt->cond);
 	ast_free(pvt);
@@ -214,6 +222,7 @@
 	.alloc = default_listener_alloc,
 	.task_pushed = default_task_pushed,
 	.emptied = default_emptied,
+	.shutdown = default_listener_shutdown,
 	.destroy = default_listener_destroy,
 };
 
@@ -571,6 +580,7 @@
 	ao2_unlink(tps_singletons, tps);
 	listener = tps->listener;
 	tps->listener = NULL;
+	listener_shutdown(listener);
 	ao2_ref(listener, -1);
 	return NULL;
 }
@@ -601,7 +611,7 @@
 {
 	struct tps_task *t;
 	int size;
-
+	
 	if (!(t = tps_taskprocessor_pop(tps))) {
 		return 0;
 	}

Modified: team/mmichelson/threadpool/tests/test_taskprocessor.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/tests/test_taskprocessor.c?view=diff&rev=376381&r1=376380&r2=376381
==============================================================================
--- team/mmichelson/threadpool/tests/test_taskprocessor.c (original)
+++ team/mmichelson/threadpool/tests/test_taskprocessor.c Thu Nov 15 22:33:53 2012
@@ -103,6 +103,7 @@
 	int num_pushed;
 	int num_emptied;
 	int num_was_empty;
+	int shutdown;
 };
 
 static void *test_alloc(struct ast_taskprocessor_listener *listener)
@@ -128,6 +129,12 @@
 	++pvt->num_emptied;
 }
 
+static void test_shutdown(struct ast_taskprocessor_listener *listener)
+{
+	struct test_listener_pvt *pvt = listener->private_data;
+	pvt->shutdown = 1;
+}
+
 static void test_destroy(void *private_data)
 {
 	struct test_listener_pvt *pvt = private_data;
@@ -138,6 +145,7 @@
 	.alloc = test_alloc,
 	.task_pushed = test_task_pushed,
 	.emptied = test_emptied,
+	.shutdown = test_shutdown,
 	.destroy = test_destroy,
 };
 




More information about the asterisk-commits mailing list