[asterisk-commits] mmichelson: branch mmichelson/pool_shark r380609 - in /team/mmichelson/pool_s...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 30 16:42:53 CST 2013


Author: mmichelson
Date: Wed Jan 30 16:42:50 2013
New Revision: 380609

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380609
Log:
Allow for pushing tasks with no associated work.

For tasks that have no direct association with other tasks, there
is no need of creating the overhead of an ast_sip_work. Simply allow
the task to be pushed directly onto the threadpool instead.

This is being used now for certain startup and shutdown operations, and
you'll soon see that it will be used for OPTIONS handling as well.
Stay tuned!


Modified:
    team/mmichelson/pool_shark/include/asterisk/res_sip.h
    team/mmichelson/pool_shark/res/res_sip.c

Modified: team/mmichelson/pool_shark/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark/include/asterisk/res_sip.h?view=diff&rev=380609&r1=380608&r2=380609
==============================================================================
--- team/mmichelson/pool_shark/include/asterisk/res_sip.h (original)
+++ team/mmichelson/pool_shark/include/asterisk/res_sip.h Wed Jan 30 16:42:50 2013
@@ -473,8 +473,11 @@
  * \brief Pushes a task into the SIP threadpool
  *
  * This uses the SIP work provided to determine how to push the task.
- *
- * \param work The SIP work to which the task belongs
+ * If the work param is NULL, then the task will be pushed into the
+ * threadpool directly. If the work is non-NULL, then the task will be
+ * queued behind other tasks associated with the work.
+ *
+ * \param work The SIP work to which the task belongs. Can be NULL
  * \param sip_task The task to execute
  * \param task_data The parameter to pass to the task when it executes
  * \retval 0 Success
@@ -485,7 +488,9 @@
 /*!
  * \brief Push a task into the SIP threadpool and wait for it to complete
  *
- * \param work The SIP work to which the task belongs
+ * Like ast_sip_push_task excepts that it blocks until the task completes.
+ *
+ * \param work The SIP work to which the task belongs. May be NULL.
  * \param sip_task The task to execute
  * \param task_data The parameter to pass to the task when it executes
  * \retval 0 Success

Modified: team/mmichelson/pool_shark/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark/res/res_sip.c?view=diff&rev=380609&r1=380608&r2=380609
==============================================================================
--- team/mmichelson/pool_shark/res/res_sip.c (original)
+++ team/mmichelson/pool_shark/res/res_sip.c Wed Jan 30 16:42:50 2013
@@ -63,14 +63,7 @@
 
 int ast_sip_register_service(pjsip_module *module)
 {
-	struct ast_sip_work *work = ast_sip_create_work();
-	int res;
-	if (!work) {
-		return -1;
-	}
-	res = ast_sip_push_task_synchronous(work, register_service, &module);
-	ast_sip_destroy_work(work);
-	return res;
+	return ast_sip_push_task_synchronous(NULL, register_service, &module);
 }
 
 static int unregister_service(void *data)
@@ -86,12 +79,7 @@
 
 void ast_sip_unregister_service(pjsip_module *module)
 {
-	struct ast_sip_work *work = ast_sip_create_work();
-	if (!work) {
-		return;
-	}
-	ast_sip_push_task_synchronous(work, unregister_service, &module);
-	ast_sip_destroy_work(work);
+	ast_sip_push_task_synchronous(NULL, unregister_service, &module);
 }
 
 AO2_GLOBAL_OBJ_STATIC(registered_authenticator);
@@ -477,7 +465,11 @@
 
 int ast_sip_push_task(struct ast_sip_work *work, int (*sip_task)(void *), void *task_data)
 {
-	return ast_taskprocessor_push(work->queue, sip_task, task_data);
+	if (work) {
+		return ast_taskprocessor_push(work->queue, sip_task, task_data);
+	} else {
+		return ast_threadpool_push(sip_threadpool, sip_task, task_data);
+	}
 }
 
 struct sync_task_data {
@@ -511,8 +503,14 @@
 	std.task = sip_task;
 	std.task_data = task_data;
 
-	if (ast_taskprocessor_push(work->queue, sync_task, &std)) {
-		return -1;
+	if (work) {
+		if (ast_taskprocessor_push(work->queue, sync_task, &std)) {
+			return -1;
+		}
+	} else {
+		if (ast_threadpool_push(sip_threadpool, sync_task, &std)) {
+			return -1;
+		}
 	}
 
 	ast_mutex_lock(&std.lock);
@@ -695,19 +693,22 @@
 
 static int unload_module(void)
 {
-	struct ast_sip_work *work;
 	ast_res_sip_destroy_configuration();
 	if (monitor_thread) {
 		stop_monitor_thread();
 	}
-	work = ast_sip_create_work();
 	/* The thread this is called from cannot call PJSIP/PJLIB functions,
 	 * so we have to push the work to the threadpool to handle
 	 */
-	ast_sip_push_task_synchronous(work, unload_pjsip, NULL);
-	ast_sip_destroy_work(work);
-
-	//ast_threadpool_shutdown(sip_threadpool);
+	ast_sip_push_task_synchronous(NULL, unload_pjsip, NULL);
+
+	/* XXX There is an issue right now that on Asterisk shutdown, res_sip
+	 * is unloaded before other SIP modules. When those other SIP modules attempt
+	 * to unregister their services, they rely on the threadpool to be present.
+	 * So for now, don't shut down the threadpool. Once module dependency stuff is
+	 * worked out, then this can be uncommented so the threadpool shuts down.
+	 */
+	/* ast_threadpool_shutdown(sip_threadpool); */
 
 	return 0;
 }




More information about the asterisk-commits mailing list