diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-06-29 10:51:00 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-06-29 10:51:00 +0000 |
commit | 53b18116f3cae8c587eafda9a24dfa2e7deda7a0 (patch) | |
tree | 0f364ec5a43c1642474f763d9fc85af5f3707151 /channel.c | |
parent | e4eae0813eeae9f935460e48a6d3332276d2120d (diff) |
Avoid potential deadlocks in channel_walk_locked, and detect serious failures
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3340 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channel.c')
-rwxr-xr-x | channel.c | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -452,6 +452,8 @@ struct ast_channel *ast_channel_walk_locked(struct ast_channel *prev) { /* Returns next channel (locked) */ struct ast_channel *l, *ret=NULL; + int retries = 0; +retry: ast_mutex_lock(&chlock); l = channels; if (!prev) { @@ -465,8 +467,21 @@ struct ast_channel *ast_channel_walk_locked(struct ast_channel *prev) ret = l->next; l = l->next; } - if (ret) - ast_mutex_lock(&ret->lock); + if (ret) { + if (ast_mutex_trylock(&ret->lock)) { + if (retries < 10) + ast_log(LOG_DEBUG, "Avoiding deadlock for '%s'\n", ret->name); + else + ast_log(LOG_WARNING, "Avoided 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 ret; |