aboutsummaryrefslogtreecommitdiffstats
path: root/channels/chan_local.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-06-27 12:19:39 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-06-27 12:19:39 +0000
commit30d145fa3a8f32f40c03732ada8ca948d5614ef6 (patch)
treea7b5d299947c6d2bf6751da92bfa5076f8be9ce7 /channels/chan_local.c
parentc446683b5b8492c28ed4376c8e1e413dcf660acd (diff)
Add proper deadlock avoidance.
(closes issue #12914) Reported by: ozan Patches: 20080625__bug12914.diff.txt uploaded by Corydon76 (license 14) Tested by: ozan git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@125740 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels/chan_local.c')
-rw-r--r--channels/chan_local.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/channels/chan_local.c b/channels/chan_local.c
index 294fbffca..783e973e0 100644
--- a/channels/chan_local.c
+++ b/channels/chan_local.c
@@ -186,13 +186,15 @@ static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_fra
while (other && ast_channel_trylock(other)) {
ast_mutex_unlock(&p->lock);
if (us && us_locked) {
- ast_channel_unlock(us);
- }
- usleep(1);
- if (us && us_locked) {
- ast_channel_lock(us);
+ do {
+ ast_channel_unlock(us);
+ usleep(1);
+ ast_channel_lock(us);
+ } while (ast_mutex_trylock(&p->lock));
+ } else {
+ usleep(1);
+ ast_mutex_lock(&p->lock);
}
- ast_mutex_lock(&p->lock);
other = isoutbound ? p->owner : p->chan;
}
@@ -510,7 +512,12 @@ static int local_hangup(struct ast_channel *ast)
if (!p)
return -1;
- ast_mutex_lock(&p->lock);
+ while (ast_mutex_trylock(&p->lock)) {
+ ast_channel_unlock(ast);
+ usleep(1);
+ ast_channel_lock(ast);
+ }
+
isoutbound = IS_OUTBOUND(ast, p);
if (isoutbound) {
const char *status = pbx_builtin_getvar_helper(p->chan, "DIALSTATUS");