[asterisk-commits] dlee: branch dlee/ASTERISK-194630-startup-deadlock r398378 - /team/dlee/ASTER...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Sep 5 11:17:00 CDT 2013


Author: dlee
Date: Thu Sep  5 11:16:58 2013
New Revision: 398378

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=398378
Log:
Properly handle lock_tracking allocation failures

Modified:
    team/dlee/ASTERISK-194630-startup-deadlock/main/lock.c

Modified: team/dlee/ASTERISK-194630-startup-deadlock/main/lock.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-194630-startup-deadlock/main/lock.c?view=diff&rev=398378&r1=398377&r2=398378
==============================================================================
--- team/dlee/ASTERISK-194630-startup-deadlock/main/lock.c (original)
+++ team/dlee/ASTERISK-194630-startup-deadlock/main/lock.c Thu Sep  5 11:16:58 2013
@@ -95,7 +95,7 @@
 		abort();
 #else
 		pthread_mutex_unlock(&reentrancy_lock.mutex);
-		return;
+		return NULL;
 #endif
 	}
 
@@ -194,7 +194,7 @@
 	case EBUSY:
 		__ast_mutex_logger("%s line %d (%s): Error: attempt to destroy locked mutex '%s'.\n",
 				   filename, lineno, func, mutex_name);
-		if (t->tracking) {
+		if (lt) {
 			ast_reentrancy_lock(lt);
 			__ast_mutex_logger("%s line %d (%s): Error: '%s' was locked here.\n",
 				    lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
@@ -214,7 +214,7 @@
 		__ast_mutex_logger("%s line %d (%s): Error destroying mutex %s: %s\n",
 				   filename, lineno, func, mutex_name, strerror(res));
 	}
-	if (t->tracking) {
+	if (lt) {
 		ast_reentrancy_lock(lt);
 		lt->file[0] = filename;
 		lt->lineno[0] = lineno;
@@ -263,7 +263,7 @@
 		lt = ast_get_reentrancy(&t->track);
 	}
 
-	if (t->tracking) {
+	if (lt) {
 #ifdef HAVE_BKTR
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy != AST_MAX_REENTRANCY) {
@@ -323,7 +323,7 @@
 #endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
 
 #ifdef DEBUG_THREADS
-	if (t->tracking && !res) {
+	if (lt && !res) {
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy < AST_MAX_REENTRANCY) {
 			lt->file[lt->reentrancy] = filename;
@@ -336,10 +336,8 @@
 							   filename, lineno, func, mutex_name);
 		}
 		ast_reentrancy_unlock(lt);
-		if (t->tracking) {
-			ast_mark_lock_acquired(t);
-		}
-	} else if (t->tracking) {
+		ast_mark_lock_acquired(t);
+	} else if (lt) {
 #ifdef HAVE_BKTR
 		if (lt->reentrancy) {
 			ast_reentrancy_lock(lt);
@@ -394,7 +392,7 @@
 		lt = ast_get_reentrancy(&t->track);
 	}
 
-	if (t->tracking) {
+	if (lt) {
 #ifdef HAVE_BKTR
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy != AST_MAX_REENTRANCY) {
@@ -412,7 +410,7 @@
 	res = pthread_mutex_trylock(&t->mutex);
 
 #ifdef DEBUG_THREADS
-	if (t->tracking && !res) {
+	if (lt && !res) {
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy < AST_MAX_REENTRANCY) {
 			lt->file[lt->reentrancy] = filename;
@@ -425,10 +423,8 @@
 					   filename, lineno, func, mutex_name);
 		}
 		ast_reentrancy_unlock(lt);
-		if (t->tracking) {
-			ast_mark_lock_acquired(t);
-		}
-	} else if (t->tracking) {
+		ast_mark_lock_acquired(t);
+	} else if (lt) {
 		ast_mark_lock_failed(t);
 	}
 #endif /* DEBUG_THREADS */
@@ -465,7 +461,7 @@
 		lt = ast_get_reentrancy(&t->track);
 	}
 
-	if (t->tracking) {
+	if (lt) {
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy && (lt->thread[ROFFSET] != pthread_self())) {
 			__ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
@@ -574,7 +570,7 @@
 		lt = ast_get_reentrancy(&t->track);
 	}
 
-	if (t->tracking) {
+	if (lt) {
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy && (lt->thread[ROFFSET] != pthread_self())) {
 			__ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
@@ -622,7 +618,7 @@
 		__ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",
 				   filename, lineno, func, strerror(res));
 		DO_THREAD_CRASH;
-	} else if (t->tracking) {
+	} else if (lt) {
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy < AST_MAX_REENTRANCY) {
 			lt->file[lt->reentrancy] = filename;
@@ -681,7 +677,7 @@
 		lt = ast_get_reentrancy(&t->track);
 	}
 
-	if (t->tracking) {
+	if (lt) {
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy && (lt->thread[ROFFSET] != pthread_self())) {
 			__ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
@@ -728,7 +724,7 @@
 		__ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",
 				   filename, lineno, func, strerror(res));
 		DO_THREAD_CRASH;
-	} else if (t->tracking) {
+	} else if (lt) {
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy < AST_MAX_REENTRANCY) {
 			lt->file[lt->reentrancy] = filename;
@@ -815,7 +811,7 @@
 		__ast_mutex_logger("%s line %d (%s): Error destroying rwlock %s: %s\n",
 				filename, lineno, func, rwlock_name, strerror(res));
 	}
-	if (t->tracking && lt) {
+	if (lt) {
 		ast_reentrancy_lock(lt);
 		lt->file[0] = filename;
 		lt->lineno[0] = lineno;
@@ -863,7 +859,7 @@
 		lt = ast_get_reentrancy(&t->track);
 	}
 
-	if (t->tracking) {
+	if (lt) {
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy) {
 			int i;
@@ -948,7 +944,7 @@
 		lt = ast_get_reentrancy(&t->track);
 	}
 
-	if (t->tracking) {
+	if (lt) {
 #ifdef HAVE_BKTR
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy != AST_MAX_REENTRANCY) {
@@ -974,7 +970,7 @@
 				if (wait_time > reported_wait && (wait_time % 5) == 0) {
 					__ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for readlock '%s'?\n",
 						filename, line, func, (int)wait_time, name);
-					if (t->tracking) {
+					if (lt) {
 						ast_reentrancy_lock(lt);
 #ifdef HAVE_BKTR
 						__dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
@@ -998,7 +994,7 @@
 #endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
 
 #ifdef DEBUG_THREADS
-	if (!res && t->tracking) {
+	if (!res && lt) {
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy < AST_MAX_REENTRANCY) {
 			lt->file[lt->reentrancy] = filename;
@@ -1008,10 +1004,8 @@
 			lt->reentrancy++;
 		}
 		ast_reentrancy_unlock(lt);
-		if (t->tracking) {
-			ast_mark_lock_acquired(t);
-		}
-	} else if (t->tracking) {
+		ast_mark_lock_acquired(t);
+	} else if (lt) {
 #ifdef HAVE_BKTR
 		if (lt->reentrancy) {
 			ast_reentrancy_lock(lt);
@@ -1066,7 +1060,7 @@
 		lt = ast_get_reentrancy(&t->track);
 	}
 
-	if (t->tracking) {
+	if (lt) {
 #ifdef HAVE_BKTR
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy != AST_MAX_REENTRANCY) {
@@ -1092,7 +1086,7 @@
 				if (wait_time > reported_wait && (wait_time % 5) == 0) {
 					__ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for writelock '%s'?\n",
 						filename, line, func, (int)wait_time, name);
-					if (t->tracking) {
+					if (lt) {
 						ast_reentrancy_lock(lt);
 #ifdef HAVE_BKTR
 						__dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
@@ -1116,7 +1110,7 @@
 #endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
 
 #ifdef DEBUG_THREADS
-	if (!res && t->tracking) {
+	if (!res && lt) {
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy < AST_MAX_REENTRANCY) {
 			lt->file[lt->reentrancy] = filename;
@@ -1126,10 +1120,8 @@
 			lt->reentrancy++;
 		}
 		ast_reentrancy_unlock(lt);
-		if (t->tracking) {
-			ast_mark_lock_acquired(t);
-		}
-	} else if (t->tracking) {
+		ast_mark_lock_acquired(t);
+	} else if (lt) {
 #ifdef HAVE_BKTR
 		if (lt->reentrancy) {
 			ast_reentrancy_lock(lt);
@@ -1138,13 +1130,9 @@
 		} else {
 			bt = NULL;
 		}
-		if (t->tracking) {
-			ast_remove_lock_info(t, bt);
-		}
-#else
-		if (t->tracking) {
-			ast_remove_lock_info(t);
-		}
+		ast_remove_lock_info(t, bt);
+#else
+		ast_remove_lock_info(t);
 #endif
 	}
 	if (res) {
@@ -1188,7 +1176,7 @@
 		lt = ast_get_reentrancy(&t->track);
 	}
 
-	if (t->tracking) {
+	if (lt) {
 #ifdef HAVE_BKTR
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy != AST_MAX_REENTRANCY) {
@@ -1222,7 +1210,7 @@
 #endif
 
 #ifdef DEBUG_THREADS
-	if (!res && t->tracking) {
+	if (!res && lt) {
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy < AST_MAX_REENTRANCY) {
 			lt->file[lt->reentrancy] = filename;
@@ -1232,10 +1220,8 @@
 			lt->reentrancy++;
 		}
 		ast_reentrancy_unlock(lt);
-		if (t->tracking) {
-			ast_mark_lock_acquired(t);
-		}
-	} else if (t->tracking) {
+		ast_mark_lock_acquired(t);
+	} else if (lt) {
 #ifdef HAVE_BKTR
 		if (lt->reentrancy) {
 			ast_reentrancy_lock(lt);
@@ -1290,7 +1276,7 @@
 		lt = ast_get_reentrancy(&t->track);
 	}
 
-	if (t->tracking) {
+	if (lt) {
 #ifdef HAVE_BKTR
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy != AST_MAX_REENTRANCY) {
@@ -1324,7 +1310,7 @@
 #endif
 
 #ifdef DEBUG_THREADS
-	if (!res && t->tracking) {
+	if (!res && lt) {
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy < AST_MAX_REENTRANCY) {
 			lt->file[lt->reentrancy] = filename;
@@ -1334,10 +1320,8 @@
 			lt->reentrancy++;
 		}
 		ast_reentrancy_unlock(lt);
-		if (t->tracking) {
-			ast_mark_lock_acquired(t);
-		}
-	} else if (t->tracking) {
+		ast_mark_lock_acquired(t);
+	} else if (lt) {
 #ifdef HAVE_BKTR
 		if (lt->reentrancy) {
 			ast_reentrancy_lock(lt);
@@ -1346,13 +1330,9 @@
 		} else {
 			bt = NULL;
 		}
-		if (t->tracking) {
-			ast_remove_lock_info(t, bt);
-		}
-#else
-		if (t->tracking) {
-			ast_remove_lock_info(t);
-		}
+		ast_remove_lock_info(t, bt);
+#else
+		ast_remove_lock_info(t);
 #endif
 	}
 	if (res) {
@@ -1395,7 +1375,7 @@
 		lt = ast_get_reentrancy(&t->track);
 	}
 
-	if (t->tracking) {
+	if (lt) {
 #ifdef HAVE_BKTR
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy != AST_MAX_REENTRANCY) {
@@ -1413,7 +1393,7 @@
 	res = pthread_rwlock_tryrdlock(&t->lock);
 
 #ifdef DEBUG_THREADS
-	if (!res && t->tracking) {
+	if (!res && lt) {
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy < AST_MAX_REENTRANCY) {
 			lt->file[lt->reentrancy] = filename;
@@ -1423,10 +1403,8 @@
 			lt->reentrancy++;
 		}
 		ast_reentrancy_unlock(lt);
-		if (t->tracking) {
-			ast_mark_lock_acquired(t);
-		}
-	} else if (t->tracking) {
+		ast_mark_lock_acquired(t);
+	} else if (lt) {
 		ast_mark_lock_failed(t);
 	}
 #endif /* DEBUG_THREADS */
@@ -1464,7 +1442,7 @@
 		lt = ast_get_reentrancy(&t->track);
 	}
 
-	if (t->tracking) {
+	if (lt) {
 #ifdef HAVE_BKTR
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy != AST_MAX_REENTRANCY) {
@@ -1482,7 +1460,7 @@
 	res = pthread_rwlock_trywrlock(&t->lock);
 
 #ifdef DEBUG_THREADS
-	if (!res && t->tracking) {
+	if (!res && lt) {
 		ast_reentrancy_lock(lt);
 		if (lt->reentrancy < AST_MAX_REENTRANCY) {
 			lt->file[lt->reentrancy] = filename;
@@ -1493,7 +1471,7 @@
 		}
 		ast_reentrancy_unlock(lt);
 		ast_mark_lock_acquired(t);
-	} else if (t->tracking) {
+	} else if (lt) {
 		ast_mark_lock_failed(t);
 	}
 #endif /* DEBUG_THREADS */




More information about the asterisk-commits mailing list