summaryrefslogtreecommitdiff
path: root/channel.c
diff options
context:
space:
mode:
authorMark Spencer <markster@digium.com>2004-06-29 12:38:04 +0000
committerMark Spencer <markster@digium.com>2004-06-29 12:38:04 +0000
commit6195ae7453514f69455c05c72b99954b2acb49ef (patch)
treec174191e77cb02106581facc32eeb6f81817be39 /channel.c
parent779140b94cefd6142898786126913bff7b8f25fa (diff)
Perform deadlock avoidance on initial entry, too
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3343 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channel.c')
-rwxr-xr-xchannel.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/channel.c b/channel.c
index 510e0c0d1..4447c2755 100755
--- a/channel.c
+++ b/channel.c
@@ -451,14 +451,28 @@ void ast_channel_undefer_dtmf(struct ast_channel *chan)
struct ast_channel *ast_channel_walk_locked(struct ast_channel *prev)
{
/* Returns next channel (locked) */
- struct ast_channel *l, *ret=NULL;
+ struct ast_channel *l, *ret;
int retries = 0;
retry:
+ ret=NULL;
ast_mutex_lock(&chlock);
l = channels;
if (!prev) {
- if (l)
- ast_mutex_lock(&l->lock);
+ if (l) {
+ if (ast_mutex_trylock(&l->lock)) {
+ if (retries < 10)
+ ast_log(LOG_DEBUG, "Avoiding initial deadlock for '%s'\n", ret->name);
+ else
+ ast_log(LOG_WARNING, "Avoided initial deadlock for '%s', %d retries!\n", ret->name, retries);
+ ast_mutex_unlock(&chlock);
+ if (retries < 10) {
+ usleep(1);
+ retries++;
+ goto retry;
+ } else
+ return NULL;
+ }
+ }
ast_mutex_unlock(&chlock);
return l;
}