[asterisk-commits] rmudgett: branch group/bridge_construction r382659 - in /team/group/bridge_co...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Mar 7 16:45:54 CST 2013
Author: rmudgett
Date: Thu Mar 7 16:45:51 2013
New Revision: 382659
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382659
Log:
Pull common code into the bridge_channel state change routines.
Make ast_bridge_change_state_nolock() and ast_bridge_change_state() not
change the state if the current state is not
AST_BRIDGE_CHANNEL_STATE_WAIT.
Modified:
team/group/bridge_construction/bridges/bridge_builtin_interval_features.c
team/group/bridge_construction/include/asterisk/bridging.h
team/group/bridge_construction/main/bridging.c
Modified: team/group/bridge_construction/bridges/bridge_builtin_interval_features.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/bridges/bridge_builtin_interval_features.c?view=diff&rev=382659&r1=382658&r2=382659
==============================================================================
--- team/group/bridge_construction/bridges/bridge_builtin_interval_features.c (original)
+++ team/group/bridge_construction/bridges/bridge_builtin_interval_features.c Thu Mar 7 16:45:51 2013
@@ -58,15 +58,7 @@
ast_stream_and_wait(bridge_channel->chan, limits->duration_sound, AST_DIGIT_NONE);
}
- ao2_lock(bridge_channel);
- switch (bridge_channel->state) {
- case AST_BRIDGE_CHANNEL_STATE_WAIT:
- ast_bridge_change_state_nolock(bridge_channel, AST_BRIDGE_CHANNEL_STATE_END);
- break;
- default:
- break;
- }
- ao2_unlock(bridge_channel);
+ ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_END);
ast_test_suite_event_notify("BRIDGE_TIMELIMIT", "Channel1: %s", ast_channel_name(bridge_channel->chan));
return -1;
Modified: team/group/bridge_construction/include/asterisk/bridging.h
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/include/asterisk/bridging.h?view=diff&rev=382659&r1=382658&r2=382659
==============================================================================
--- team/group/bridge_construction/include/asterisk/bridging.h (original)
+++ team/group/bridge_construction/include/asterisk/bridging.h Thu Mar 7 16:45:51 2013
@@ -579,18 +579,21 @@
int ast_bridge_unsuspend(struct ast_bridge *bridge, struct ast_channel *chan);
/*!
- * \brief Change the state of a bridged channel without taking and releasing the bridge channel lock
+ * \brief Set bridge channel state to leave bridge (if not leaving already) with no lock.
*
* \param bridge_channel Channel to change the state on
* \param new_state The new state to place the channel into
*
- * \note Do not use this call outside the context of either interval hook callbacks or bridging core.
- * This function assumes the bridge_channel is locked.
+ * \note This API call is only meant to be used within the
+ * bridging module and hook callbacks to request the channel
+ * exit the bridge.
+ *
+ * \note This function assumes the bridge_channel is locked.
*/
void ast_bridge_change_state_nolock(struct ast_bridge_channel *bridge_channel, enum ast_bridge_channel_state new_state);
/*!
- * \brief Change the state of a bridged channel
+ * \brief Set bridge channel state to leave bridge (if not leaving already).
*
* \param bridge_channel Channel to change the state on
* \param new_state The new state to place the channel into
@@ -601,11 +604,13 @@
* ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_HANGUP);
* \endcode
*
- * This places the channel pointed to by bridge_channel into the state
- * AST_BRIDGE_CHANNEL_STATE_HANGUP.
- *
- * \note This API call is only meant to be used in feature hook callbacks to
- * request the channel exit the bridge.
+ * This places the channel pointed to by bridge_channel into the
+ * state AST_BRIDGE_CHANNEL_STATE_HANGUP if it was
+ * AST_BRIDGE_CHANNEL_STATE_WAIT before.
+ *
+ * \note This API call is only meant to be used within the
+ * bridging module and hook callbacks to request the channel
+ * exit the bridge.
*/
void ast_bridge_change_state(struct ast_bridge_channel *bridge_channel, enum ast_bridge_channel_state new_state);
Modified: team/group/bridge_construction/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/main/bridging.c?view=diff&rev=382659&r1=382658&r2=382659
==============================================================================
--- team/group/bridge_construction/main/bridging.c (original)
+++ team/group/bridge_construction/main/bridging.c Thu Mar 7 16:45:51 2013
@@ -154,6 +154,10 @@
void ast_bridge_change_state_nolock(struct ast_bridge_channel *bridge_channel, enum ast_bridge_channel_state new_state)
{
/* BUGBUG need cause code for the bridge_channel leaving the bridge. */
+ if (bridge_channel->state != AST_BRIDGE_CHANNEL_STATE_WAIT) {
+ return;
+ }
+
ast_debug(1, "Setting bridge channel %p(%s) state from:%d to:%d\n",
bridge_channel, ast_channel_name(bridge_channel->chan), bridge_channel->state,
new_state);
@@ -435,13 +439,7 @@
if (bridge->dissolved) {
/* Force out channel being pushed into a dissolved bridge. */
- switch (bridge_channel->state) {
- case AST_BRIDGE_CHANNEL_STATE_WAIT:
- ast_bridge_change_state_nolock(bridge_channel, AST_BRIDGE_CHANNEL_STATE_HANGUP);
- break;
- default:
- break;
- }
+ ast_bridge_change_state_nolock(bridge_channel, AST_BRIDGE_CHANNEL_STATE_HANGUP);
}
if (bridge_channel->state != AST_BRIDGE_CHANNEL_STATE_WAIT) {
/* Don't push a channel in the process of leaving. */
@@ -463,15 +461,7 @@
ast_debug(1, "Swapping bridge channel %p(%s) out from bridge %p so bridge channel %p(%s) can slip in\n",
bridge_channel2, ast_channel_name(bridge_channel2->chan), bridge,
bridge_channel, ast_channel_name(bridge_channel->chan));
- ao2_lock(bridge_channel2);
- switch (bridge_channel2->state) {
- case AST_BRIDGE_CHANNEL_STATE_WAIT:
- ast_bridge_change_state_nolock(bridge_channel2, AST_BRIDGE_CHANNEL_STATE_HANGUP);
- break;
- default:
- break;
- }
- ao2_unlock(bridge_channel2);
+ ast_bridge_change_state(bridge_channel2, AST_BRIDGE_CHANNEL_STATE_HANGUP);
ast_bridge_channel_pull(bridge_channel2);
}
@@ -512,15 +502,7 @@
/* BUGBUG need a cause code on the bridge for the later ejected channels. */
AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {
- ao2_lock(bridge_channel);
- switch (bridge_channel->state) {
- case AST_BRIDGE_CHANNEL_STATE_WAIT:
- ast_bridge_change_state_nolock(bridge_channel, AST_BRIDGE_CHANNEL_STATE_HANGUP);
- break;
- default:
- break;
- }
- ao2_unlock(bridge_channel);
+ ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_HANGUP);
}
}
@@ -625,15 +607,7 @@
}
/* Default hangup action. */
- ao2_lock(bridge_channel);
- switch (bridge_channel->state) {
- case AST_BRIDGE_CHANNEL_STATE_WAIT:
- ast_bridge_change_state_nolock(bridge_channel, AST_BRIDGE_CHANNEL_STATE_END);
- break;
- default:
- break;
- }
- ao2_unlock(bridge_channel);
+ ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_END);
}
static int bridge_channel_interval_ready(struct ast_bridge_channel *bridge_channel)
@@ -2324,16 +2298,7 @@
/* We are claiming the reference held by the depart thread. */
- ao2_lock(bridge_channel);
- switch (bridge_channel->state) {
- case AST_BRIDGE_CHANNEL_STATE_WAIT:
- ast_bridge_change_state_nolock(bridge_channel, AST_BRIDGE_CHANNEL_STATE_HANGUP);
- break;
- default:
- /* The channel is already leaving the bridge. */
- break;
- }
- ao2_unlock(bridge_channel);
+ ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_HANGUP);
/* Wait for the depart thread to die */
pthread_join(bridge_channel->thread, NULL);
@@ -2357,15 +2322,7 @@
return -1;
}
- ao2_lock(bridge_channel);
- switch (bridge_channel->state) {
- case AST_BRIDGE_CHANNEL_STATE_WAIT:
- ast_bridge_change_state_nolock(bridge_channel, AST_BRIDGE_CHANNEL_STATE_HANGUP);
- break;
- default:
- break;
- }
- ao2_unlock(bridge_channel);
+ ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_HANGUP);
ao2_unlock(bridge);
More information about the asterisk-commits
mailing list