[asterisk-commits] dlee: branch dlee/ASTERISK-22455-deadlock r398496 - in /team/dlee/ASTERISK-22...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Sep 5 16:20:41 CDT 2013
Author: dlee
Date: Thu Sep 5 16:20:40 2013
New Revision: 398496
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=398496
Log:
Properly suspend lock info during condition wait
Modified:
team/dlee/ASTERISK-22455-deadlock/include/asterisk/lock.h
team/dlee/ASTERISK-22455-deadlock/main/lock.c
team/dlee/ASTERISK-22455-deadlock/main/utils.c
Modified: team/dlee/ASTERISK-22455-deadlock/include/asterisk/lock.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22455-deadlock/include/asterisk/lock.h?view=diff&rev=398496&r1=398495&r2=398496
==============================================================================
--- team/dlee/ASTERISK-22455-deadlock/include/asterisk/lock.h (original)
+++ team/dlee/ASTERISK-22455-deadlock/include/asterisk/lock.h Thu Sep 5 16:20:40 2013
@@ -281,12 +281,16 @@
#else
void ast_remove_lock_info(void *lock_addr);
#endif /* HAVE_BKTR */
+void ast_suspend_lock_info(void *lock_addr);
+void ast_restore_lock_info(void *lock_addr);
#else
#ifdef HAVE_BKTR
#define ast_remove_lock_info(ignore,me)
#else
#define ast_remove_lock_info(ignore)
#endif /* HAVE_BKTR */
+#define ast_suspend_lock_info(ignore);
+#define ast_restore_lock_info(ignore);
#endif /* !defined(LOW_MEMORY) */
/*!
Modified: team/dlee/ASTERISK-22455-deadlock/main/lock.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22455-deadlock/main/lock.c?view=diff&rev=398496&r1=398495&r2=398496
==============================================================================
--- team/dlee/ASTERISK-22455-deadlock/main/lock.c (original)
+++ team/dlee/ASTERISK-22455-deadlock/main/lock.c Thu Sep 5 16:20:40 2013
@@ -515,9 +515,6 @@
struct ast_lock_track *lt;
struct ast_lock_track lt_orig;
int canlog = strcmp(filename, "logger.c") & t->tracking;
-#ifdef HAVE_BKTR
- struct ast_bt *bt = NULL;
-#endif
#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
@@ -561,11 +558,7 @@
lt->reentrancy = 0;
ast_reentrancy_unlock(lt);
-#ifdef HAVE_BKTR
- ast_remove_lock_info(t, bt);
-#else
- ast_remove_lock_info(t);
-#endif
+ ast_suspend_lock_info(t);
}
#endif /* DEBUG_THREADS */
@@ -586,12 +579,7 @@
lt->reentr_mutex = reentr_mutex_orig;
ast_reentrancy_unlock(lt);
-#ifdef HAVE_BKTR
- bt = <->backtrace[ROFFSET];
- ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
-#else
- ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t);
-#endif
+ ast_restore_lock_info(t);
}
#endif /* DEBUG_THREADS */
@@ -608,9 +596,6 @@
struct ast_lock_track *lt;
struct ast_lock_track lt_orig;
int canlog = strcmp(filename, "logger.c") & t->tracking;
-#ifdef HAVE_BKTR
- struct ast_bt *bt = NULL;
-#endif
#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
@@ -654,11 +639,7 @@
lt->reentrancy = 0;
ast_reentrancy_unlock(lt);
-#ifdef HAVE_BKTR
- ast_remove_lock_info(t, bt);
-#else
- ast_remove_lock_info(t);
-#endif
+ ast_suspend_lock_info(t);
}
#endif /* DEBUG_THREADS */
@@ -679,12 +660,7 @@
lt->reentr_mutex = reentr_mutex_orig;
ast_reentrancy_unlock(lt);
-#ifdef HAVE_BKTR
- bt = <->backtrace[ROFFSET];
- ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
-#else
- ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t);
-#endif
+ ast_suspend_lock_info(t);
}
#endif /* DEBUG_THREADS */
Modified: team/dlee/ASTERISK-22455-deadlock/main/utils.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22455-deadlock/main/utils.c?view=diff&rev=398496&r1=398495&r2=398496
==============================================================================
--- team/dlee/ASTERISK-22455-deadlock/main/utils.c (original)
+++ team/dlee/ASTERISK-22455-deadlock/main/utils.c Thu Sep 5 16:20:40 2013
@@ -585,6 +585,8 @@
enum ast_lock_type type;
/*! This thread is waiting on this lock */
int pending:2;
+ /*! A condition as suspended this lock */
+ int suspended:1;
#ifdef HAVE_BKTR
struct ast_bt *backtrace;
#endif
@@ -771,6 +773,60 @@
return 0;
}
+void ast_suspend_lock_info(void *lock_addr)
+{
+ struct thr_lock_info *lock_info;
+ int i = 0;
+
+ if (!(lock_info = ast_threadstorage_get(&thread_lock_info, sizeof(*lock_info)))) {
+ return;
+ }
+
+ pthread_mutex_lock(&lock_info->lock);
+
+ for (i = lock_info->num_locks - 1; i >= 0; i--) {
+ if (lock_info->locks[i].lock_addr == lock_addr)
+ break;
+ }
+
+ if (i == -1) {
+ /* Lock not found :( */
+ pthread_mutex_unlock(&lock_info->lock);
+ return;
+ }
+
+ lock_info->locks[i].suspended = 1;
+
+ pthread_mutex_unlock(&lock_info->lock);
+}
+
+void ast_restore_lock_info(void *lock_addr)
+{
+ struct thr_lock_info *lock_info;
+ int i = 0;
+
+ if (!(lock_info = ast_threadstorage_get(&thread_lock_info, sizeof(*lock_info))))
+ return;
+
+ pthread_mutex_lock(&lock_info->lock);
+
+ for (i = lock_info->num_locks - 1; i >= 0; i--) {
+ if (lock_info->locks[i].lock_addr == lock_addr)
+ break;
+ }
+
+ if (i == -1) {
+ /* Lock not found :( */
+ pthread_mutex_unlock(&lock_info->lock);
+ return;
+ }
+
+ lock_info->locks[i].suspended = 0;
+
+ pthread_mutex_unlock(&lock_info->lock);
+}
+
+
#ifdef HAVE_BKTR
void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt)
#else
@@ -864,7 +920,7 @@
ast_mutex_t *lock;
struct ast_lock_track *lt;
- ast_str_append(str, 0, "=== ---> %sLock #%d (%s): %s %d %s %s %p (%d)\n",
+ ast_str_append(str, 0, "=== ---> %sLock #%d (%s): %s %d %s %s %p (%d%s)\n",
lock_info->locks[i].pending > 0 ? "Waiting for " :
lock_info->locks[i].pending < 0 ? "Tried and failed to get " : "", i,
lock_info->locks[i].file,
@@ -872,7 +928,8 @@
lock_info->locks[i].line_num,
lock_info->locks[i].func, lock_info->locks[i].lock_name,
lock_info->locks[i].lock_addr,
- lock_info->locks[i].times_locked);
+ lock_info->locks[i].times_locked,
+ lock_info->locks[i].suspended ? " - suspended" : "");
#ifdef HAVE_BKTR
append_backtrace_information(str, lock_info->locks[i].backtrace);
#endif
@@ -981,20 +1038,32 @@
pthread_mutex_lock(&lock_infos_lock.mutex);
AST_LIST_TRAVERSE(&lock_infos, lock_info, entry) {
int i;
- if (lock_info->num_locks) {
- ast_str_append(&str, 0, "=== Thread ID: 0x%lx (%s)\n", (long) lock_info->thread_id,
- lock_info->thread_name);
- pthread_mutex_lock(&lock_info->lock);
- for (i = 0; str && i < lock_info->num_locks; i++) {
- append_lock_information(&str, lock_info, i);
+ int header_printed = 0;
+ pthread_mutex_lock(&lock_info->lock);
+ for (i = 0; str && i < lock_info->num_locks; i++) {
+ /* Don't show suspended locks */
+ if (lock_info->locks[i].suspended) {
+ continue;
}
- pthread_mutex_unlock(&lock_info->lock);
- if (!str)
- break;
+
+ if (!header_printed) {
+ ast_str_append(&str, 0, "=== Thread ID: 0x%lx (%s)\n", (long) lock_info->thread_id,
+ lock_info->thread_name);
+ header_printed = 1;
+ }
+
+ append_lock_information(&str, lock_info, i);
+ }
+ pthread_mutex_unlock(&lock_info->lock);
+ if (!str) {
+ break;
+ }
+ if (header_printed) {
ast_str_append(&str, 0, "=== -------------------------------------------------------------------\n"
- "===\n");
- if (!str)
- break;
+ "===\n");
+ }
+ if (!str) {
+ break;
}
}
pthread_mutex_unlock(&lock_infos_lock.mutex);
More information about the asterisk-commits
mailing list