[asterisk-commits] rmudgett: branch 10 r367978 - in /branches/10: ./ channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed May 30 12:39:29 CDT 2012
Author: rmudgett
Date: Wed May 30 12:39:24 2012
New Revision: 367978
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=367978
Log:
Fix deadlock when executing CLI "pri show channels" and "ss7 show channels" commands.
* Fix sig_pri_lock_owner() to avoid deadlock properly.
* Code pri_grab() better.
* Fix sig_ss7_lock_owner() to avoid deadlock properly.
* Code ss7_grab() better.
(closes issue ASTERISK-19854)
Reported by: Jaxon
Patches:
jira_asterisk_19854_v1.8.6.patch (license #5621) patch uploaded by rmudgett (Modified to do the same thing to sig_ss7)
Tested by: Jaxon
........
Merged revisions 367976 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Modified:
branches/10/ (props changed)
branches/10/channels/sig_pri.c
branches/10/channels/sig_ss7.c
Propchange: branches/10/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.
Modified: branches/10/channels/sig_pri.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/channels/sig_pri.c?view=diff&rev=367978&r1=367977&r2=367978
==============================================================================
--- branches/10/channels/sig_pri.c (original)
+++ branches/10/channels/sig_pri.c Wed May 30 12:39:24 2012
@@ -115,13 +115,6 @@
#define DCHAN_AVAILABLE (DCHAN_NOTINALARM | DCHAN_UP)
-#define PRI_DEADLOCK_AVOIDANCE(p) \
- do { \
- sig_pri_unlock_private(p); \
- usleep(1); \
- sig_pri_lock_private(p); \
- } while (0)
-
static int pri_active_dchan_index(struct sig_pri_span *pri);
static const char *sig_pri_call_level2str(enum sig_pri_call_level level)
@@ -349,23 +342,23 @@
p->calls->deadlock_avoidance_private(p->chan_pvt);
} else {
/* Fallback to the old way if callback not present. */
- PRI_DEADLOCK_AVOIDANCE(p);
+ sig_pri_unlock_private(p);
+ sched_yield();
+ sig_pri_lock_private(p);
}
}
static void pri_grab(struct sig_pri_chan *p, struct sig_pri_span *pri)
{
- int res;
-
/* Grab the lock first */
- do {
- res = ast_mutex_trylock(&pri->lock);
- if (res) {
- sig_pri_deadlock_avoidance_private(p);
- }
- } while (res);
+ while (ast_mutex_trylock(&pri->lock)) {
+ /* Avoid deadlock */
+ sig_pri_deadlock_avoidance_private(p);
+ }
/* Then break the poll */
- pthread_kill(pri->master, SIGURG);
+ if (pri->master != AST_PTHREADT_NULL) {
+ pthread_kill(pri->master, SIGURG);
+ }
}
/*!
@@ -1203,10 +1196,13 @@
/* We got the lock */
break;
}
- /* We must unlock the PRI to avoid the possibility of a deadlock */
+
+ /* Avoid deadlock */
+ sig_pri_unlock_private(pri->pvts[chanpos]);
ast_mutex_unlock(&pri->lock);
- sig_pri_deadlock_avoidance_private(pri->pvts[chanpos]);
+ sched_yield();
ast_mutex_lock(&pri->lock);
+ sig_pri_lock_private(pri->pvts[chanpos]);
}
}
Modified: branches/10/channels/sig_ss7.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/channels/sig_ss7.c?view=diff&rev=367978&r1=367977&r2=367978
==============================================================================
--- branches/10/channels/sig_ss7.c (original)
+++ branches/10/channels/sig_ss7.c Wed May 30 12:39:24 2012
@@ -67,13 +67,6 @@
return "Unknown";
}
-#define SIG_SS7_DEADLOCK_AVOIDANCE(p) \
- do { \
- sig_ss7_unlock_private(p); \
- usleep(1); \
- sig_ss7_lock_private(p); \
- } while (0)
-
static void sig_ss7_unlock_private(struct sig_ss7_chan *p)
{
if (p->calls->unlock_private) {
@@ -94,7 +87,9 @@
p->calls->deadlock_avoidance_private(p->chan_pvt);
} else {
/* Fallback to the old way if callback not present. */
- SIG_SS7_DEADLOCK_AVOIDANCE(p);
+ sig_ss7_unlock_private(p);
+ sched_yield();
+ sig_ss7_lock_private(p);
}
}
@@ -314,10 +309,13 @@
/* We got the lock */
break;
}
- /* We must unlock the SS7 to avoid the possibility of a deadlock */
+
+ /* Avoid deadlock */
+ sig_ss7_unlock_private(ss7->pvts[chanpos]);
ast_mutex_unlock(&ss7->lock);
- sig_ss7_deadlock_avoidance_private(ss7->pvts[chanpos]);
+ sched_yield();
ast_mutex_lock(&ss7->lock);
+ sig_ss7_lock_private(ss7->pvts[chanpos]);
}
}
@@ -1266,17 +1264,15 @@
static void ss7_grab(struct sig_ss7_chan *pvt, struct sig_ss7_linkset *ss7)
{
- int res;
/* Grab the lock first */
- do {
- res = ast_mutex_trylock(&ss7->lock);
- if (res) {
- sig_ss7_deadlock_avoidance_private(pvt);
- }
- } while (res);
+ while (ast_mutex_trylock(&ss7->lock)) {
+ /* Avoid deadlock */
+ sig_ss7_deadlock_avoidance_private(pvt);
+ }
/* Then break the poll */
- if (ss7->master != AST_PTHREADT_NULL)
+ if (ss7->master != AST_PTHREADT_NULL) {
pthread_kill(ss7->master, SIGURG);
+ }
}
/*!
More information about the asterisk-commits
mailing list