From 671499c8b26568aa01fe385da7645880969fd1a6 Mon Sep 17 00:00:00 2001 From: Richard Mudgett Date: Wed, 9 Jan 2013 20:56:23 +0000 Subject: * Found some more places to use ast_channel_lock_both(). * Minor optimization in ast_rtp_instance_early_bridge(). git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@378789 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/rtp_engine.c | 33 ++++++++------------------------- main/udptl.c | 7 +------ 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/main/rtp_engine.c b/main/rtp_engine.c index 7cbfba0ca..a674cabab 100644 --- a/main/rtp_engine.c +++ b/main/rtp_engine.c @@ -1467,12 +1467,7 @@ enum ast_bridge_result ast_rtp_instance_bridge(struct ast_channel *c0, struct as } /* Lock both channels so we can look for the glue that binds them together */ - ast_channel_lock(c0); - while (ast_channel_trylock(c1)) { - ast_channel_unlock(c0); - usleep(1); - ast_channel_lock(c0); - } + ast_channel_lock_both(c0, c1); /* Ensure neither channel got hungup during lock avoidance */ if (ast_check_hangup(c0) || ast_check_hangup(c1)) { @@ -1548,7 +1543,9 @@ enum ast_bridge_result ast_rtp_instance_bridge(struct ast_channel *c0, struct as } /* If we have gotten to a local bridge make sure that both sides have the same local bridge callback and that they are DTMF compatible */ - if ((audio_glue0_res == AST_RTP_GLUE_RESULT_LOCAL || audio_glue1_res == AST_RTP_GLUE_RESULT_LOCAL) && ((instance0->engine->local_bridge != instance1->engine->local_bridge) || (instance0->engine->dtmf_compatible && !instance0->engine->dtmf_compatible(c0, instance0, c1, instance1)))) { + if ((audio_glue0_res == AST_RTP_GLUE_RESULT_LOCAL || audio_glue1_res == AST_RTP_GLUE_RESULT_LOCAL) + && (instance0->engine->local_bridge != instance1->engine->local_bridge + || (instance0->engine->dtmf_compatible && !instance0->engine->dtmf_compatible(c0, instance0, c1, instance1)))) { res = AST_BRIDGE_FAILED_NOWARN; goto done; } @@ -1712,26 +1709,16 @@ int ast_rtp_instance_early_bridge(struct ast_channel *c0, struct ast_channel *c1 enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID; struct ast_format_cap *cap0 = ast_format_cap_alloc_nolock(); struct ast_format_cap *cap1 = ast_format_cap_alloc_nolock(); - int res = 0; /* If there is no second channel just immediately bail out, we are of no use in that scenario */ - if (!c1) { + if (!c1 || !cap1 || !cap0) { ast_format_cap_destroy(cap0); ast_format_cap_destroy(cap1); return -1; } /* Lock both channels so we can look for the glue that binds them together */ - ast_channel_lock(c0); - while (ast_channel_trylock(c1)) { - ast_channel_unlock(c0); - usleep(1); - ast_channel_lock(c0); - } - - if (!cap1 || !cap0) { - goto done; - } + ast_channel_lock_both(c0, c1); /* Grab glue that binds each channel to something using the RTP engine */ if (!(glue0 = ast_rtp_instance_get_glue(ast_channel_tech(c0)->type)) || !(glue1 = ast_rtp_instance_get_glue(ast_channel_tech(c1)->type))) { @@ -1774,8 +1761,6 @@ int ast_rtp_instance_early_bridge(struct ast_channel *c0, struct ast_channel *c1 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", ast_channel_name(c0), c1 ? ast_channel_name(c1) : ""); } - res = 0; - done: ast_channel_unlock(c0); ast_channel_unlock(c1); @@ -1790,11 +1775,9 @@ done: unref_instance_cond(&tinstance0); unref_instance_cond(&tinstance1); - if (!res) { - ast_debug(1, "Setting early bridge SDP of '%s' with that of '%s'\n", ast_channel_name(c0), c1 ? ast_channel_name(c1) : ""); - } + ast_debug(1, "Setting early bridge SDP of '%s' with that of '%s'\n", ast_channel_name(c0), c1 ? ast_channel_name(c1) : ""); - return res; + return 0; } int ast_rtp_red_init(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations) diff --git a/main/udptl.c b/main/udptl.c index bc96790fd..37f04d530 100644 --- a/main/udptl.c +++ b/main/udptl.c @@ -1206,12 +1206,7 @@ int ast_udptl_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, void *pvt1; int to; - ast_channel_lock(c0); - while (ast_channel_trylock(c1)) { - ast_channel_unlock(c0); - usleep(1); - ast_channel_lock(c0); - } + ast_channel_lock_both(c0, c1); pr0 = get_proto(c0); pr1 = get_proto(c1); if (!pr0) { -- cgit v1.2.3