[asterisk-commits] rmudgett: branch 1.8 r367976 - in /branches/1.8/channels: sig_pri.c sig_ss7.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed May 30 12:21:47 CDT 2012
Author: rmudgett
Date: Wed May 30 12:21:43 2012
New Revision: 367976
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=367976
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
Modified:
branches/1.8/channels/sig_pri.c
branches/1.8/channels/sig_ss7.c
Modified: branches/1.8/channels/sig_pri.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/sig_pri.c?view=diff&rev=367976&r1=367975&r2=367976
==============================================================================
--- branches/1.8/channels/sig_pri.c (original)
+++ branches/1.8/channels/sig_pri.c Wed May 30 12:21:43 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)
@@ -345,16 +338,17 @@
static inline int 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) {
- PRI_DEADLOCK_AVOIDANCE(p);
- }
- } while (res);
+ while (ast_mutex_trylock(&pri->lock)) {
+ /* Avoid deadlock */
+ sig_pri_unlock_private(p);
+ sched_yield();
+ sig_pri_lock_private(p);
+ }
/* Then break the poll */
- pthread_kill(pri->master, SIGURG);
+ if (pri->master != AST_PTHREADT_NULL) {
+ pthread_kill(pri->master, SIGURG);
+ }
return 0;
}
@@ -1193,10 +1187,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);
- PRI_DEADLOCK_AVOIDANCE(pri->pvts[chanpos]);
+ sched_yield();
ast_mutex_lock(&pri->lock);
+ sig_pri_lock_private(pri->pvts[chanpos]);
}
}
Modified: branches/1.8/channels/sig_ss7.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/sig_ss7.c?view=diff&rev=367976&r1=367975&r2=367976
==============================================================================
--- branches/1.8/channels/sig_ss7.c (original)
+++ branches/1.8/channels/sig_ss7.c Wed May 30 12:21:43 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) {
@@ -304,10 +297,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(ss7->pvts[chanpos]);
+ sched_yield();
ast_mutex_lock(&ss7->lock);
+ sig_ss7_lock_private(ss7->pvts[chanpos]);
}
}
@@ -1256,17 +1252,17 @@
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(pvt);
- }
- } while (res);
+ while (ast_mutex_trylock(&ss7->lock)) {
+ /* Avoid deadlock */
+ sig_ss7_unlock_private(pvt);
+ sched_yield();
+ sig_ss7_lock_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