[asterisk-commits] file: branch file/bridging r79081 - in /team/file/bridging: include/asterisk/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Aug 10 13:54:57 CDT 2007


Author: file
Date: Fri Aug 10 13:54:56 2007
New Revision: 79081

URL: http://svn.digium.com/view/asterisk?view=rev&rev=79081
Log:
Keep a count of how many channels are involved in a bridge. This serves as a method of making sure all the threads involved in the thread are synchronized and out of the bridge before actually destroying it.

Modified:
    team/file/bridging/include/asterisk/bridging.h
    team/file/bridging/main/bridging.c

Modified: team/file/bridging/include/asterisk/bridging.h
URL: http://svn.digium.com/view/asterisk/team/file/bridging/include/asterisk/bridging.h?view=diff&rev=79081&r1=79080&r2=79081
==============================================================================
--- team/file/bridging/include/asterisk/bridging.h (original)
+++ team/file/bridging/include/asterisk/bridging.h Fri Aug 10 13:54:56 2007
@@ -96,6 +96,7 @@
 
 struct ast_bridge {
 	ast_mutex_t lock;                                    /*! Lock to protect the bridge */
+	int num;                                             /*! Number of channels involved in the bridge */
 	struct ast_flags notify_flags;                       /*! Notify flags, used to indicate that the bridge should do something */
 	struct ast_flags feature_flags;                      /*! Feature flags */
 	struct ast_bridge_technology *technology;            /*! Technology in use on the bridge */

Modified: team/file/bridging/main/bridging.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/main/bridging.c?view=diff&rev=79081&r1=79080&r2=79081
==============================================================================
--- team/file/bridging/main/bridging.c (original)
+++ team/file/bridging/main/bridging.c Fri Aug 10 13:54:56 2007
@@ -311,6 +311,14 @@
 		ast_mutex_unlock(&bridge->lock);
 	}
 
+	ast_debug(1, "Waiting for bridge %p to calm down... it currently has %d channels in it\n", bridge, bridge->num);
+
+	/* As each bridged channel removes themselves from the bridge they decrement this value atomically as a last action, so once this value is 0 we can be certain no channel
+	 * is part of the bridge any longer.
+	 */
+	while (bridge->num)
+		usleep(1);
+
 	ast_debug(1, "Proceeding with bridge destruction of %p\n", bridge);
 
 	/* Pass off the bridge to the technology to destroy if needed */
@@ -459,6 +467,9 @@
 	/* Before we actually become part of this bridge make sure we are in the signalling wait state */
 	bridge_channel->state = AST_BRIDGE_CHANNEL_STATE_WAIT;
 
+	/* Increment bridged channel count */
+	ast_atomic_fetchadd_int(&bridge->num, +1);
+
 	/* Make the bridged channel part of the bridge */
 	AST_LIST_INSERT_TAIL(&bridge->channels, bridge_channel, list);
 
@@ -499,6 +510,9 @@
 	/* Remove ourselves from the bridge */
 	AST_LIST_REMOVE(&bridge->channels, bridge_channel, list);
 
+	/* Decrement bridged channel count */
+	ast_atomic_fetchadd_int(&bridge->num, -1);
+
 	/* Restore original formats if need be */
 	if (bridge_channel->chan->readformat != formats[0]) {
 		ast_debug(1, "Bridge is returning %p to read format %s(%d)\n", bridge_channel, ast_getformatname(formats[0]), formats[0]);




More information about the asterisk-commits mailing list