[asterisk-commits] file: branch file/bridging-phase2 r180638 - /team/file/bridging-phase2/bridges/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 6 13:43:59 CST 2009


Author: file
Date: Fri Mar  6 13:43:48 2009
New Revision: 180638

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=180638
Log:
Improve our handling of the thread being used for each multiplexed thread. Suspending a channel will no longer cause the underlying thread to go away. It will just wait until the channel is unsuspended. Additionally keep the thread for a multiplexed thread structure around for 60 seconds afterwards in case channels want to use it. This way we don't incur the cost of creating a new thread.

Modified:
    team/file/bridging-phase2/bridges/bridge_multiplexed.c

Modified: team/file/bridging-phase2/bridges/bridge_multiplexed.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/bridging-phase2/bridges/bridge_multiplexed.c?view=diff&rev=180638&r1=180637&r2=180638
==============================================================================
--- team/file/bridging-phase2/bridges/bridge_multiplexed.c (original)
+++ team/file/bridging-phase2/bridges/bridge_multiplexed.c Fri Mar  6 13:43:48 2009
@@ -48,6 +48,9 @@
 
 /*! \brief Number of channels we handle in a single thread */
 #define MULTIPLEXED_MAX_CHANNELS 8
+
+/*! \brief Lifetime that an idle muliplexed thread should live (in ms) */
+#define MULTIPLEXED_IDLE_LIFETIME 60000
 
 /*! \brief Structure which represents a single thread handling multiple 2 channel bridges */
 struct multiplexed_thread {
@@ -200,7 +203,7 @@
 {
 	int nudge = 0;
 
-	if (multiplexed_thread->thread == AST_PTHREADT_NULL) {
+	if (!multiplexed_thread->waiting) {
 		return;
 	}
 
@@ -223,13 +226,6 @@
 	ao2_lock(multiplexed_threads);
 
 	multiplexed_thread->count -= 2;
-
-	if (!multiplexed_thread->count) {
-		ast_debug(1, "Unlinking multiplexed thread '%p' since nobody is using it anymore\n", multiplexed_thread);
-		ao2_unlink(multiplexed_threads, multiplexed_thread);
-	}
-
-	multiplexed_nudge(multiplexed_thread);
 
 	ao2_unlock(multiplexed_threads);
 
@@ -253,8 +249,10 @@
 		int outfd = -1;
 
 		/* Move channels around so not just the first one gets priority */
-		memmove(multiplexed_thread->chans, multiplexed_thread->chans + 1, sizeof(struct ast_channel *) * (multiplexed_thread->service_count - 1));
-		multiplexed_thread->chans[multiplexed_thread->service_count - 1] = first;
+		if (multiplexed_thread->service_count) {
+			memmove(multiplexed_thread->chans, multiplexed_thread->chans + 1, sizeof(struct ast_channel *) * (multiplexed_thread->service_count - 1));
+			multiplexed_thread->chans[multiplexed_thread->service_count - 1] = first;
+		}
 
 		multiplexed_thread->waiting = 1;
 		ao2_unlock(multiplexed_thread);
@@ -273,8 +271,12 @@
 		}
 
 		if (!multiplexed_thread->timeout) {
-			multiplexed_thread_trigger_timeout(multiplexed_thread);
-			multiplexed_thread_update_timeout(multiplexed_thread, NULL);
+			if (multiplexed_thread->count) {
+				multiplexed_thread_trigger_timeout(multiplexed_thread);
+				multiplexed_thread_update_timeout(multiplexed_thread, NULL);
+			} else {
+				multiplexed_thread->thread = AST_PTHREADT_STOP;
+			}
 		}
 
 		if (winner && winner->bridge) {
@@ -287,6 +289,7 @@
 	ast_debug(1, "Stopping actual thread for multiplexed thread '%p'\n", multiplexed_thread);
 
 	ao2_unlock(multiplexed_thread);
+	ao2_unlink(multiplexed_threads, multiplexed_thread);
 	ao2_ref(multiplexed_thread, -1);
 
 	return NULL;
@@ -296,7 +299,6 @@
 static void multiplexed_add_or_remove(struct multiplexed_thread *multiplexed_thread, struct ast_channel *chan, int add, struct ast_bridge *bridge)
 {
 	int i, removed = 0;
-	pthread_t thread = AST_PTHREADT_NULL;
 
 	ao2_lock(multiplexed_thread);
 
@@ -325,18 +327,13 @@
 			ast_debug(1, "Failed to create an actual thread for multiplexed thread '%p', trying next time\n", multiplexed_thread);
 		}
 	} else if (!multiplexed_thread->service_count && multiplexed_thread->thread != AST_PTHREADT_NULL) {
-		thread = multiplexed_thread->thread;
-		multiplexed_thread->thread = AST_PTHREADT_STOP;
+		multiplexed_thread->timeout = MULTIPLEXED_IDLE_LIFETIME;
 	} else if (!add && removed) {
 		multiplexed_thread_update_timeout(multiplexed_thread, NULL);
 		memmove(multiplexed_thread->chans + i, multiplexed_thread->chans + i + 1, sizeof(struct ast_channel *) * (MULTIPLEXED_MAX_CHANNELS - (i + 1)));
 	}
 
 	ao2_unlock(multiplexed_thread);
-
-	if (thread != AST_PTHREADT_NULL) {
-		pthread_join(thread, NULL);
-	}
 
 	return;
 }




More information about the asterisk-commits mailing list