[svn-commits] rmudgett: branch rmudgett/bridge_phase r381515 - /team/rmudgett/bridge_phase/...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Feb 14 17:00:01 CST 2013


Author: rmudgett
Date: Thu Feb 14 16:59:57 2013
New Revision: 381515

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=381515
Log:
Make bridges self managing if there is no external reference.

The ast_bridge ao2 object now destroys the bridging thread if it is
running in the destructor.  The bridge thread no longer needs a bridge
reference since it will die when the destructor runs.

Modified:
    team/rmudgett/bridge_phase/main/bridging.c

Modified: team/rmudgett/bridge_phase/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/main/bridging.c?view=diff&rev=381515&r1=381514&r2=381515
==============================================================================
--- team/rmudgett/bridge_phase/main/bridging.c (original)
+++ team/rmudgett/bridge_phase/main/bridging.c Thu Feb 14 16:59:57 2013
@@ -566,7 +566,13 @@
 	}
 }
 
-/*! \brief Bridge thread function */
+/*!
+ * \brief Bridge thread function
+ *
+ * \note The thread does not have its own reference to the
+ * bridge.  The bridge ao2 object destructor will stop the
+ * thread if it is running.
+ */
 static void *bridge_thread(void *data)
 {
 	struct ast_bridge *bridge = data;
@@ -659,6 +665,16 @@
 	ast_assert(AST_LIST_EMPTY(&bridge->channels));
 	ast_assert(AST_LIST_EMPTY(&bridge->depart_wait));
 
+	ao2_lock(bridge);
+	if (bridge->thread != AST_PTHREADT_NULL) {
+		bridge_stop(bridge);
+	}
+	ao2_unlock(bridge);
+
+	if (bridge->callid) {
+		bridge->callid = ast_callid_unref(bridge->callid);
+	}
+
 	/* Pass off the bridge to the technology to destroy if needed */
 	if (bridge->technology->destroy) {
 		ast_debug(1, "Giving bridge technology %s the bridge structure %p to destroy\n", bridge->technology->name, bridge);
@@ -757,23 +773,9 @@
 
 int ast_bridge_destroy(struct ast_bridge *bridge)
 {
+	ast_debug(1, "Telling all channels in bridge %p to leave the party\n", bridge);
 	ao2_lock(bridge);
-
-	if (bridge->callid) {
-/* BUGBUG the bridge callid needs to be verified.  Move to the bridge destructor. */
-		bridge->callid = ast_callid_unref(bridge->callid);
-	}
-
-	if (bridge->thread != AST_PTHREADT_NULL) {
-/* BUGBUG this needs to be moved to the bridge ao2 destructor. */
-		bridge_stop(bridge);
-	}
-
-	ast_debug(1, "Telling all channels in bridge %p to leave the party\n", bridge);
-
-	/* Drop every bridged channel, the last one will cause the bridge thread (if it exists) to exit */
 	bridge_force_out_all(bridge);
-
 	ao2_unlock(bridge);
 
 	ao2_ref(bridge, -1);
@@ -1386,10 +1388,8 @@
 		if (bridge_channel->bridge->thread == AST_PTHREADT_NULL
 			&& (bridge_channel->bridge->technology->capabilities & AST_BRIDGE_CAPABILITY_THREAD)) {
 			ast_debug(1, "Starting a bridge thread for bridge %p\n", bridge_channel->bridge);
-			ao2_ref(bridge_channel->bridge, +1);
 			if (ast_pthread_create(&bridge_channel->bridge->thread, NULL, bridge_thread, bridge_channel->bridge)) {
 				ast_debug(1, "Failed to create a bridge thread for bridge %p, giving it another go.\n", bridge_channel->bridge);
-				ao2_ref(bridge_channel->bridge, -1);
 				continue;
 			}
 		}




More information about the svn-commits mailing list