[asterisk-commits] murf: branch murf/threadpool r148823 - /team/murf/threadpool/main/pbx.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Oct 14 08:57:34 CDT 2008


Author: murf
Date: Tue Oct 14 08:57:34 2008
New Revision: 148823

URL: http://svn.digium.com/view/asterisk?view=rev&rev=148823
Log:
OK, that was easy. pbx thread is now 
given to a threadpool to execute.

Now, all I have to do is fix all the bugs
I introduced and make it work!

Really, it'd be better to create the threadpool
at init/load time, rather than at the first
call, but this is an experiment...



Modified:
    team/murf/threadpool/main/pbx.c

Modified: team/murf/threadpool/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/murf/threadpool/main/pbx.c?view=diff&rev=148823&r1=148822&r2=148823
==============================================================================
--- team/murf/threadpool/main/pbx.c (original)
+++ team/murf/threadpool/main/pbx.c Tue Oct 14 08:57:34 2008
@@ -65,6 +65,7 @@
 #include "asterisk/module.h"
 #include "asterisk/indications.h"
 #include "asterisk/taskprocessor.h"
+#include "asterisk/threadpool.h"
 
 /*!
  * \note I M P O R T A N T :
@@ -3975,7 +3976,7 @@
 	ast_free(e);
 }
 
-static void *pbx_thread(void *data)
+static void pbx_thread(void *data)
 {
 	/* Oh joyeous kernel, we're a new thread, with nothing to do but
 	   answer this channel and get it going.
@@ -3990,14 +3991,11 @@
 	__ast_pbx_run(c);
 	decrease_call_count();
 
-	pthread_exit(NULL);
-
-	return NULL;
 }
 
 enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
 {
-	pthread_t t;
+	static struct ast_threadpool *pool = NULL;
 
 	if (!c) {
 		ast_log(LOG_WARNING, "Asked to start thread on NULL channel?\n");
@@ -4007,8 +4005,13 @@
 	if (increase_call_count(c))
 		return AST_PBX_CALL_LIMIT;
 
-	/* Start a new thread, and get something handling this channel. */
-	if (ast_pthread_create_detached(&t, NULL, pbx_thread, c)) {
+	if (!pool) {
+		pool = ast_threadpool_create("PBX Threadpool", 100, 10000, 35000, pbx_thread, "pbx_thread");
+		ast_log(LOG_NOTICE,"Created new threadpool: 'PBX Threadpool', with 100 threads, dynamic max of 10,000.\n");
+	}
+
+	/* submit this job to the threadpool, and get something handling this channel. */
+	if (ast_threadpool_run_default_func(pool, c)) {
 		ast_log(LOG_WARNING, "Failed to create new channel thread\n");
 		return AST_PBX_FAILED;
 	}




More information about the asterisk-commits mailing list