aboutsummaryrefslogtreecommitdiffstats
path: root/channels/chan_local.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-08-14 13:12:39 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-08-14 13:12:39 +0000
commit88922ffffc6d07f58d839d9e7c7e56a67a67c5e6 (patch)
tree3aac5de46fa4f0126e75a546abf3163b8259f992 /channels/chan_local.c
parent1312721eaccb04c5ba9ced6d9e5ca6834a8aa51c (diff)
Make check_bridge back off if it cant get all the locks it wants
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1321 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels/chan_local.c')
-rwxr-xr-xchannels/chan_local.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/channels/chan_local.c b/channels/chan_local.c
index 9b60a0263..1cafbebcc 100755
--- a/channels/chan_local.c
+++ b/channels/chan_local.c
@@ -134,21 +134,27 @@ static void check_bridge(struct local_pvt *p, int isoutbound)
return;
if (isoutbound && p->chan && p->chan->bridge && p->owner) {
/* Masquerade bridged channel into owner */
- /* Lock other side first */
- ast_mutex_lock(&p->chan->bridge->lock);
- ast_mutex_lock(&p->owner->lock);
- ast_channel_masquerade(p->owner, p->chan->bridge);
- ast_mutex_unlock(&p->owner->lock);
- ast_mutex_unlock(&p->chan->bridge->lock);
- p->alreadymasqed = 1;
+ /* Lock everything we need, one by one, and give up if
+ we can't get everything. Remember, we'll get another
+ chance in just a little bit */
+ if (!ast_mutex_trylock(&p->chan->bridge->lock)) {
+ if (!ast_mutex_trylock(&p->owner->lock)) {
+ ast_channel_masquerade(p->owner, p->chan->bridge);
+ p->alreadymasqed = 1;
+ ast_mutex_unlock(&p->owner->lock);
+ }
+ ast_mutex_unlock(&p->chan->bridge->lock);
+ }
} else if (!isoutbound && p->owner && p->owner->bridge && p->chan) {
/* Masquerade bridged channel into chan */
- ast_mutex_lock(&p->owner->bridge->lock);
- ast_mutex_lock(&p->chan->lock);
- ast_channel_masquerade(p->chan, p->owner->bridge);
- ast_mutex_unlock(&p->chan->lock);
- ast_mutex_unlock(&p->owner->bridge->lock);
- p->alreadymasqed = 1;
+ if (!ast_mutex_trylock(&p->owner->bridge->lock)) {
+ if (!ast_mutex_trylock(&p->chan->lock)) {
+ ast_channel_masquerade(p->chan, p->owner->bridge);
+ p->alreadymasqed = 1;
+ ast_mutex_unlock(&p->chan->lock);
+ }
+ ast_mutex_unlock(&p->owner->bridge->lock);
+ }
}
}