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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 28 18:20:24 CST 2013


Author: mmichelson
Date: Mon Jan 28 18:20:21 2013
New Revision: 380293

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380293
Log:
Add possibility for workers to call common functions on start and end.

This makes it possible for threads in the SIP threadpool to register
with PJLIB when they start up.


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

Modified: team/mmichelson/pool_shark/include/asterisk/threadpool.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark/include/asterisk/threadpool.h?view=diff&rev=380293&r1=380292&r2=380293
==============================================================================
--- team/mmichelson/pool_shark/include/asterisk/threadpool.h (original)
+++ team/mmichelson/pool_shark/include/asterisk/threadpool.h Mon Jan 28 18:20:21 2013
@@ -105,6 +105,20 @@
 	 * beyond this number of threads.
 	 */
 	int max_size;
+	/*!
+	 * \brief Function to call when a thread starts
+	 *
+	 * This is useful if there is something common that all threads
+	 * in a threadpool need to do when they start.
+	 */
+	void (*thread_start)(void);
+	/*!
+	 * \brief Function to call when a thread ends
+	 *
+	 * This is useful if there is common cleanup to execute when
+	 * a thread completes
+	 */
+	void (*thread_end)(void);
 };
 
 /*!

Modified: team/mmichelson/pool_shark/main/threadpool.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark/main/threadpool.c?view=diff&rev=380293&r1=380292&r2=380293
==============================================================================
--- team/mmichelson/pool_shark/main/threadpool.c (original)
+++ team/mmichelson/pool_shark/main/threadpool.c Mon Jan 28 18:20:21 2013
@@ -984,7 +984,13 @@
 {
 	struct worker_thread *worker = arg;
 
+	if (worker->options.thread_start) {
+		worker->options.thread_start();
+	}
 	worker_active(worker);
+	if (worker->options.thread_end) {
+		worker->options.thread_end();
+	}
 	return NULL;
 }
 

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=380293&r1=380292&r2=380293
==============================================================================
--- team/mmichelson/pool_shark/res/res_sip.c (original)
+++ team/mmichelson/pool_shark/res/res_sip.c Mon Jan 28 18:20:21 2013
@@ -532,6 +532,14 @@
 	.on_rx_request = unhandled_on_rx_request,
 };
 
+static void sip_thread_start(void)
+{
+	pj_thread_desc desc;
+	pj_thread_t *thread;
+
+	pj_thread_register("Asterisk Thread", desc, &thread);
+}
+
 static int load_module(void)
 {
     /* The third parameter is just copied from
@@ -551,6 +559,7 @@
 		.max_size = 0,
 		.idle_timeout = 60,
 		.initial_size = 0,
+		.thread_start = sip_thread_start,
 	};
 	sip_threadpool = ast_threadpool_create("SIP", NULL, &options);
 




More information about the asterisk-commits mailing list