aboutsummaryrefslogtreecommitdiffstats
path: root/channels
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-28 17:15:41 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-28 17:15:41 +0000
commit8b1d81f4eed25b1f883d68871a9e5d4c655e888b (patch)
tree3f2ce6672be5fc2196c5c81011a47e0d6a580af0 /channels
parent940f913146cc96cda9132600151d40ee85680ee6 (diff)
Make some deadlock related fixes. These bugs were discovered and reported
internally at Digium by Steve Pitts. - Fix up chan_local to ensure that the channel lock is held before the local pvt lock. - Don't hold the channel lock when executing the timing function, as it can cause a deadlock when using chan_local. This actually changes the code back to be how it was before the change for issue #10765. But, I added some other locking that I think will prevent the problem reported there, as well. git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@100581 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_local.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/channels/chan_local.c b/channels/chan_local.c
index cbf7f7f48..3795be9c6 100644
--- a/channels/chan_local.c
+++ b/channels/chan_local.c
@@ -154,8 +154,6 @@ static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_fra
{
struct ast_channel *other = NULL;
-retrylock:
-
/* Recalculate outbound channel */
other = isoutbound ? p->owner : p->chan;
@@ -173,27 +171,28 @@ retrylock:
ast_clear_flag(p, LOCAL_GLARE_DETECT);
return 0;
}
- if (ast_mutex_trylock(&other->lock)) {
- /* Failed to lock. Release main lock and try again */
- ast_mutex_unlock(&p->lock);
- if (us) {
- if (ast_mutex_unlock(&us->lock)) {
- ast_log(LOG_WARNING, "%s wasn't locked while sending %d/%d\n",
- us->name, f->frametype, f->subclass);
- us = NULL;
- }
+
+ ast_mutex_unlock(&p->lock);
+
+ /* Ensure that we have both channels locked */
+ if (us) {
+ while (ast_channel_trylock(other)) {
+ ast_channel_unlock(us);
+ usleep(1);
+ ast_channel_lock(us);
}
- /* Wait just a bit */
- usleep(1);
- /* Only we can destroy ourselves, so we can't disappear here */
- if (us)
- ast_mutex_lock(&us->lock);
- ast_mutex_lock(&p->lock);
- goto retrylock;
+ } else {
+ ast_channel_lock(other);
}
+
ast_queue_frame(other, f);
- ast_mutex_unlock(&other->lock);
+
+ ast_channel_unlock(other);
+
+ ast_mutex_lock(&p->lock);
+
ast_clear_flag(p, LOCAL_GLARE_DETECT);
+
return 0;
}