[svn-commits] rmudgett: branch rmudgett/bridge_phase r381764 - in /team/rmudgett/bridge_pha...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Feb 19 12:55:05 CST 2013


Author: rmudgett
Date: Tue Feb 19 12:55:01 2013
New Revision: 381764

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=381764
Log:
* Change bridge_thread() to just wait for something to happen if there is
no bridge thread loop callback.

* Rename several functions and make semi-public.
generic_thread_loop() -> ast_bridge_thread_generic()
bridge_poke() -> ast_bridge_poke()

* Rename bridge_channel_poke() to bridge_channel_poke_locked().

* Extract ast_bridge_channel_poke() and make semi-public.

Modified:
    team/rmudgett/bridge_phase/bridges/bridge_multiplexed.c
    team/rmudgett/bridge_phase/bridges/bridge_simple.c
    team/rmudgett/bridge_phase/bridges/bridge_softmix.c
    team/rmudgett/bridge_phase/include/asterisk/bridging_technology.h
    team/rmudgett/bridge_phase/main/bridging.c

Modified: team/rmudgett/bridge_phase/bridges/bridge_multiplexed.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/bridges/bridge_multiplexed.c?view=diff&rev=381764&r1=381763&r2=381764
==============================================================================
--- team/rmudgett/bridge_phase/bridges/bridge_multiplexed.c (original)
+++ team/rmudgett/bridge_phase/bridges/bridge_multiplexed.c Tue Feb 19 12:55:01 2013
@@ -459,8 +459,9 @@
 	}
 
 	/* Find the channel we actually want to write to */
-	if (!(other = (AST_LIST_FIRST(&bridge->channels) == bridge_channel ? AST_LIST_LAST(&bridge->channels) : AST_LIST_FIRST(&bridge->channels)))) {
-		return AST_BRIDGE_WRITE_FAILED;
+	other = AST_LIST_FIRST(&bridge->channels);
+	if (other == bridge_channel) {
+		other = AST_LIST_LAST(&bridge->channels);
 	}
 
 	/* The bridging core takes care of freeing the passed in frame. */

Modified: team/rmudgett/bridge_phase/bridges/bridge_simple.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/bridges/bridge_simple.c?view=diff&rev=381764&r1=381763&r2=381764
==============================================================================
--- team/rmudgett/bridge_phase/bridges/bridge_simple.c (original)
+++ team/rmudgett/bridge_phase/bridges/bridge_simple.c Tue Feb 19 12:55:01 2013
@@ -76,8 +76,9 @@
 	}
 
 	/* Find the channel we actually want to write to */
-	if (!(other = (AST_LIST_FIRST(&bridge->channels) == bridge_channel ? AST_LIST_LAST(&bridge->channels) : AST_LIST_FIRST(&bridge->channels)))) {
-		return AST_BRIDGE_WRITE_FAILED;
+	other = AST_LIST_FIRST(&bridge->channels);
+	if (other == bridge_channel) {
+		other = AST_LIST_LAST(&bridge->channels);
 	}
 
 	/* The bridging core takes care of freeing the passed in frame. */
@@ -96,6 +97,7 @@
 	.capabilities = AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_THREAD,
 	.preference = AST_BRIDGE_PREFERENCE_MEDIUM,
 	.join = simple_bridge_join,
+	.thread_loop = ast_bridge_thread_generic,
 	.write = simple_bridge_write,
 };
 

Modified: team/rmudgett/bridge_phase/bridges/bridge_softmix.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/bridges/bridge_softmix.c?view=diff&rev=381764&r1=381763&r2=381764
==============================================================================
--- team/rmudgett/bridge_phase/bridges/bridge_softmix.c (original)
+++ team/rmudgett/bridge_phase/bridges/bridge_softmix.c Tue Feb 19 12:55:01 2013
@@ -920,7 +920,7 @@
 	.join = softmix_bridge_join,
 	.leave = softmix_bridge_leave,
 	.write = softmix_bridge_write,
-	.thread = softmix_bridge_thread,
+	.thread_loop = softmix_bridge_thread,
 	.poke_channel = softmix_bridge_poke_channel,
 };
 

Modified: team/rmudgett/bridge_phase/include/asterisk/bridging_technology.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/include/asterisk/bridging_technology.h?view=diff&rev=381764&r1=381763&r2=381764
==============================================================================
--- team/rmudgett/bridge_phase/include/asterisk/bridging_technology.h (original)
+++ team/rmudgett/bridge_phase/include/asterisk/bridging_technology.h Tue Feb 19 12:55:01 2013
@@ -67,8 +67,8 @@
 	enum ast_bridge_write_result (*write)(struct ast_bridge *bridge, struct ast_bridge_channel *bridged_channel, struct ast_frame *frame);
 	/*! Callback for when a file descriptor trips */
 	int (*fd)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, int fd);
-	/*! Callback for replacement thread function */
-	int (*thread)(struct ast_bridge *bridge);
+	/*! Callback for bridge thread loop */
+	int (*thread_loop)(struct ast_bridge *bridge);
 	/*! Callback for poking a bridge channel thread */
 	void (*poke_channel)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
 	/*! Formats that the bridge technology supports */
@@ -126,6 +126,41 @@
 int ast_bridge_technology_unregister(struct ast_bridge_technology *technology);
 
 /*!
+ * \brief Generic bridge thread loop.
+ * \since 12.0.0
+ *
+ * \param bridge Handle this bridge thread's loop.
+ *
+ * \retval 0 on success.
+ * \retval non-zero on error.
+ */
+int ast_bridge_thread_generic(struct ast_bridge *bridge);
+
+/*!
+ * \brief Poke the bridge thread if it is not us.
+ * \since 12.0.0
+ *
+ * \param bridge What to poke.
+ *
+ * \note This function assumes the bridge is locked.
+ *
+ * \return Nothing
+ */
+void ast_bridge_poke(struct ast_bridge *bridge);
+
+/*!
+ * \brief Poke the bridge channel thread if it is not us.
+ * \since 12.0.0
+ *
+ * \param bridge_channel What to poke.
+ *
+ * \note This function assumes the bridge_channel is locked.
+ *
+ * \return Nothing
+ */
+void ast_bridge_channel_poke(struct ast_bridge_channel *bridge_channel);
+
+/*!
  * \brief Feed notification that a frame is waiting on a channel into the bridging core
  *
  * \param bridge The bridge that the notification should influence

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=381764&r1=381763&r2=381764
==============================================================================
--- team/rmudgett/bridge_phase/main/bridging.c (original)
+++ team/rmudgett/bridge_phase/main/bridging.c Tue Feb 19 12:55:01 2013
@@ -76,10 +76,12 @@
 
 int __ast_bridge_technology_register(struct ast_bridge_technology *technology, struct ast_module *module)
 {
-	struct ast_bridge_technology *current = NULL;
+	struct ast_bridge_technology *current;
 
 	/* Perform a sanity check to make sure the bridge technology conforms to our needed requirements */
-	if (ast_strlen_zero(technology->name) || !technology->capabilities || !technology->write) {
+	if (ast_strlen_zero(technology->name)
+		|| !technology->capabilities
+		|| !technology->write) {
 		ast_log(LOG_WARNING, "Bridge technology %s failed registration sanity check.\n", technology->name);
 		return -1;
 	}
@@ -110,7 +112,7 @@
 
 int ast_bridge_technology_unregister(struct ast_bridge_technology *technology)
 {
-	struct ast_bridge_technology *current = NULL;
+	struct ast_bridge_technology *current;
 
 	AST_RWLIST_WRLOCK(&bridge_technologies);
 
@@ -129,11 +131,18 @@
 	return current ? 0 : -1;
 }
 
-static void bridge_channel_poke(struct ast_bridge_channel *bridge_channel)
+void ast_bridge_channel_poke(struct ast_bridge_channel *bridge_channel)
+{
+	if (!pthread_equal(pthread_self(), bridge_channel->thread)) {
+		pthread_kill(bridge_channel->thread, SIGURG);
+		ast_cond_signal(&bridge_channel->cond);
+	}
+}
+
+static void bridge_channel_poke_locked(struct ast_bridge_channel *bridge_channel)
 {
 	ao2_lock(bridge_channel);
-	pthread_kill(bridge_channel->thread, SIGURG);
-	ast_cond_signal(&bridge_channel->cond);
+	ast_bridge_channel_poke(bridge_channel);
 	ao2_unlock(bridge_channel);
 }
 
@@ -146,11 +155,7 @@
 	/* Change the state on the bridge channel */
 	bridge_channel->state = new_state;
 
-	/* Only poke the channel's thread if it is not us */
-	if (!pthread_equal(pthread_self(), bridge_channel->thread)) {
-		pthread_kill(bridge_channel->thread, SIGURG);
-		ast_cond_signal(&bridge_channel->cond);
-	}
+	ast_bridge_channel_poke(bridge_channel);
 }
 
 void ast_bridge_change_state(struct ast_bridge_channel *bridge_channel, enum ast_bridge_channel_state new_state)
@@ -174,22 +179,12 @@
 
 	ao2_lock(bridge_channel);
 	AST_LIST_INSERT_TAIL(&bridge_channel->action_queue, dup, frame_list);
-
-	/* Only poke the channel's thread if it is not us */
-	if (!pthread_equal(pthread_self(), bridge_channel->thread)) {
-		pthread_kill(bridge_channel->thread, SIGURG);
-		ast_cond_signal(&bridge_channel->cond);
-	}
+	ast_bridge_channel_poke(bridge_channel);
 	ao2_unlock(bridge_channel);
 	return 0;
 }
 
-/*!
- * \brief Helper function to poke the bridge thread
- *
- * \note This function assumes the bridge is locked.
- */
-static void bridge_poke(struct ast_bridge *bridge)
+void ast_bridge_poke(struct ast_bridge *bridge)
 {
 	/* Poke the thread just in case */
 	if (bridge->thread != AST_PTHREADT_NULL) {
@@ -212,7 +207,7 @@
 	pthread_t thread;
 
 	bridge->stop = 1;
-	bridge_poke(bridge);
+	ast_bridge_poke(bridge);
 	thread = bridge->thread;
 	bridge->thread = AST_PTHREADT_NULL;
 	ao2_unlock(bridge);
@@ -230,7 +225,7 @@
 {
 	/* We have to make sure the bridge thread is not using the bridge array before messing with it */
 	while (bridge->waiting) {
-		bridge_poke(bridge);
+		ast_bridge_poke(bridge);
 		sched_yield();
 	}
 
@@ -254,7 +249,7 @@
 		bridge->array_size += BRIDGE_ARRAY_GROW;
 	}
 
-	bridge_poke(bridge);
+	ast_bridge_poke(bridge);
 }
 
 /*!
@@ -268,7 +263,7 @@
 
 	/* We have to make sure the bridge thread is not using the bridge array before messing with it */
 	while (bridge->waiting) {
-		bridge_poke(bridge);
+		ast_bridge_poke(bridge);
 		sched_yield();
 	}
 
@@ -534,8 +529,7 @@
 	}
 }
 
-/*! \brief Generic thread loop, TODO: Rethink this/improve it */
-static int generic_thread_loop(struct ast_bridge *bridge)
+int ast_bridge_thread_generic(struct ast_bridge *bridge)
 {
 	if (bridge->stop || bridge->refresh || !bridge->array_num) {
 		return 0;
@@ -590,21 +584,22 @@
 	/* Loop around until we are told to stop */
 	while (!bridge->stop) {
 		if (!bridge->array_num) {
-			/* Wait for a channel to be added to the bridge. */
+			/* Wait for an active channel on the bridge. */
 			ast_cond_wait(&bridge->cond, ao2_object_get_lockaddr(bridge));
 			continue;
 		}
+/* BUGBUG this is where we are going to move the smart bridge checking. */
 
 		/* In case the refresh bit was set simply set it back to off */
 		bridge->refresh = 0;
 
-		/*
-		 * Execute the appropriate thread function.  If the technology
-		 * does not provide one we use the generic one.
-		 */
-		res = bridge->technology->thread
-			? bridge->technology->thread(bridge)
-			: generic_thread_loop(bridge);
+		if (!bridge->technology->thread_loop) {
+			/* Just wait until something happens */
+			ast_cond_wait(&bridge->cond, ao2_object_get_lockaddr(bridge));
+			continue;
+		}
+
+		res = bridge->technology->thread_loop(bridge);
 		if (res) {
 			/*
 			 * A bridge error occurred.  Sleep and try again later so we
@@ -893,11 +888,11 @@
 		if (new_technology->capabilities & AST_BRIDGE_CAPABILITY_THREAD) {
 			ast_debug(1, "Telling current bridge thread for bridge %p to refresh\n", bridge);
 			bridge->refresh = 1;
-			bridge_poke(bridge);
+			ast_bridge_poke(bridge);
 		} else {
 			ast_debug(1, "Telling current bridge thread for bridge %p to stop\n", bridge);
 			bridge->stop = 1;
-			bridge_poke(bridge);
+			ast_bridge_poke(bridge);
 			thread = bridge->thread;
 			bridge->thread = AST_PTHREADT_NULL;
 		}
@@ -919,6 +914,7 @@
 		if (new_technology->create(bridge)) {
 			ast_debug(1, "Bridge technology %s failed to setup bridge structure %p\n",
 				new_technology->name, bridge);
+/* BUGBUG we should dissolve the bridge since the technology could not be setup. */
 		}
 	}
 
@@ -950,7 +946,7 @@
 		}
 
 		/* Fourth we tell them to wake up so they become aware that the above has happened */
-		bridge_channel_poke(bridge_channel2);
+		bridge_channel_poke_locked(bridge_channel2);
 	}
 
 	if (thread != AST_PTHREADT_NULL) {
@@ -2103,7 +2099,7 @@
 	if (bridge1->thread != AST_PTHREADT_NULL) {
 		ast_debug(1, "Telling bridge thread on bridge %p to stop as it is being merged into %p\n", bridge1, bridge0);
 		bridge1->stop = 1;
-		bridge_poke(bridge1);
+		ast_bridge_poke(bridge1);
 		thread = bridge1->thread;
 		bridge1->thread = AST_PTHREADT_NULL;
 	}
@@ -2145,7 +2141,7 @@
 		}
 
 		/* Poke the bridge channel, this will cause it to wake up and execute the proper threading model for the new bridge it is in */
-		bridge_channel_poke(bridge_channel);
+		bridge_channel_poke_locked(bridge_channel);
 	}
 
 	ast_debug(1, "Merged channels from bridge %p into bridge %p\n", bridge1, bridge0);




More information about the svn-commits mailing list