From 441da04c0ba70e7d77304c5394bd83d834aae432 Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Wed, 25 Jun 2008 01:13:38 +0000 Subject: [PATCH] Merged revisions 124966 via svnmerge from https://origsvn.digium.com/svn/asterisk/trunk ................ r124966 | tilghman | 2008-06-24 20:08:37 -0500 (Tue, 24 Jun 2008) | 15 lines Merged revisions 124965 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r124965 | tilghman | 2008-06-24 19:46:24 -0500 (Tue, 24 Jun 2008) | 7 lines Pvt deadlock causes some channels to get stuck in Reserved status. (closes issue #12621) Reported by: fabianoheringer Patches: 20080612__bug12621.diff.txt uploaded by Corydon76 (license 14) Tested by: fabianoheringer ........ ................ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@124967 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_dahdi.c | 7 ++++--- include/asterisk/lock.h | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c index 8192d752e4..86f13b5275 100644 --- a/channels/chan_dahdi.c +++ b/channels/chan_dahdi.c @@ -5208,10 +5208,11 @@ static struct ast_frame *dahdi_read(struct ast_channel *ast) int index; void *readbuf; struct ast_frame *f; - - ast_mutex_lock(&p->lock); - + while (ast_mutex_trylock(&p->lock)) { + CHANNEL_DEADLOCK_AVOIDANCE(ast); + } + index = dahdi_get_index(ast, p, 0); /* Hang up if we don't really exist */ diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h index e7dfb3075d..1a294d400c 100644 --- a/include/asterisk/lock.h +++ b/include/asterisk/lock.h @@ -204,6 +204,20 @@ int ast_find_lock_info(void *lock_addr, const char **filename, int *lineno, cons * used during deadlock avoidance, to preserve the original location where * a lock was originally acquired. */ +#define CHANNEL_DEADLOCK_AVOIDANCE(chan) \ + do { \ + const char *__filename, *__func, *__mutex_name; \ + int __lineno; \ + int __res = ast_find_lock_info(&chan->lock_dont_use, &__filename, &__lineno, &__func, &__mutex_name); \ + ast_channel_unlock(chan); \ + usleep(1); \ + if (__res < 0) { /* Shouldn't ever happen, but just in case... */ \ + ast_channel_lock(chan); \ + } else { \ + __ast_pthread_mutex_lock(__filename, __lineno, __func, __mutex_name, &chan->lock_dont_use); \ + } \ + } while (0) + #define DEADLOCK_AVOIDANCE(lock) \ do { \ const char *__filename, *__func, *__mutex_name; \ @@ -1067,6 +1081,11 @@ static inline int _ast_rwlock_trywrlock(ast_rwlock_t *lock, const char *name, #else /* !DEBUG_THREADS */ +#define CHANNEL_DEADLOCK_AVOIDANCE(chan) \ + ast_channel_lock(chan); \ + usleep(1); \ + ast_channel_unlock(chan); + #define DEADLOCK_AVOIDANCE(lock) \ ast_mutex_lock(lock); \ usleep(1); \