[asterisk-commits] russell: trunk r84272 - in /trunk: ./ include/asterisk/lock.h main/utils.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Oct 1 16:15:57 CDT 2007


Author: russell
Date: Mon Oct  1 16:15:57 2007
New Revision: 84272

URL: http://svn.digium.com/view/asterisk?view=rev&rev=84272
Log:
Merged revisions 84271 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r84271 | russell | 2007-10-01 16:07:06 -0500 (Mon, 01 Oct 2007) | 4 lines

Fulfull a feature request from Qwell on the "core show locks" output.  It will
now note the lock type for each lock that a thread holds.
(mutex, rdlock, or wrlock)

........

Modified:
    trunk/   (props changed)
    trunk/include/asterisk/lock.h
    trunk/main/utils.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/include/asterisk/lock.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/lock.h?view=diff&rev=84272&r1=84271&r2=84272
==============================================================================
--- trunk/include/asterisk/lock.h (original)
+++ trunk/include/asterisk/lock.h Mon Oct  1 16:15:57 2007
@@ -126,6 +126,12 @@
 
 static pthread_mutex_t empty_mutex;
 
+enum ast_lock_type {
+	AST_MUTEX,
+	AST_RDLOCK,
+	AST_WRLOCK,
+};
+
 /*!
  * \brief Store lock info for the current thread
  *
@@ -134,8 +140,8 @@
  * lock info struct.  The lock is marked as pending as the thread is waiting
  * on the lock.  ast_mark_lock_acquired() will mark it as held by this thread.
  */
-void ast_store_lock_info(const char *filename, int line_num, 
-	const char *func, const char *lock_name, void *lock_addr);
+void ast_store_lock_info(enum ast_lock_type type, const char *filename,
+	int line_num, const char *func, const char *lock_name, void *lock_addr);
 
 /*!
  * \brief Mark the last lock as acquired
@@ -249,7 +255,7 @@
 	int canlog = strcmp(filename, "logger.c");
 
 	if (t->track)
-		ast_store_lock_info(filename, lineno, func, mutex_name, &t->mutex);
+		ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
 
 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS)
 	if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
@@ -333,7 +339,7 @@
 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 
 	if (t->track)
-		ast_store_lock_info(filename, lineno, func, mutex_name, &t->mutex);
+		ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
 
 	if (!(res = pthread_mutex_trylock(&t->mutex))) {
 		if (t->track)
@@ -469,7 +475,7 @@
 		DO_THREAD_CRASH;
 	} else {
 		if (t->track)
-			ast_store_lock_info(filename, lineno, func, mutex_name, &t->mutex);
+			ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
 
 		if (t->reentrancy < AST_MAX_REENTRANCY) {
 			t->file[t->reentrancy] = filename;
@@ -530,7 +536,7 @@
 		DO_THREAD_CRASH;
 	} else {
 		if (t->track)
-			ast_store_lock_info(filename, lineno, func, mutex_name, &t->mutex);
+			ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
 
 		if (t->reentrancy < AST_MAX_REENTRANCY) {
 			t->file[t->reentrancy] = filename;
@@ -722,7 +728,7 @@
 	const char *file, int line, const char *func)
 {
 	int res;
-	ast_store_lock_info(file, line, func, name, lock);
+	ast_store_lock_info(AST_RDLOCK, file, line, func, name, lock);
 	res = pthread_rwlock_rdlock(lock);
 	if (!res)
 		ast_mark_lock_acquired();
@@ -738,7 +744,7 @@
 	const char *file, int line, const char *func)
 {
 	int res;
-	ast_store_lock_info(file, line, func, name, lock);
+	ast_store_lock_info(AST_WRLOCK, file, line, func, name, lock);
 	res = pthread_rwlock_wrlock(lock);
 	if (!res)
 		ast_mark_lock_acquired();
@@ -754,7 +760,7 @@
 	const char *file, int line, const char *func)
 {
 	int res;
-	ast_store_lock_info(file, line, func, name, lock);
+	ast_store_lock_info(AST_RDLOCK, file, line, func, name, lock);
 	res = pthread_rwlock_tryrdlock(lock);
 	if (!res)
 		ast_mark_lock_acquired();
@@ -770,7 +776,7 @@
 	const char *file, int line, const char *func)
 {
 	int res;
-	ast_store_lock_info(file, line, func, name, lock);
+	ast_store_lock_info(AST_WRLOCK, file, line, func, name, lock);
 	res = pthread_rwlock_trywrlock(lock);
 	if (!res)
 		ast_mark_lock_acquired();
@@ -780,6 +786,7 @@
 }
 
 #else
+
 static inline int ast_rwlock_unlock(ast_rwlock_t *prwlock)
 {
 	return pthread_rwlock_unlock(prwlock);

Modified: trunk/main/utils.c
URL: http://svn.digium.com/view/asterisk/trunk/main/utils.c?view=diff&rev=84272&r1=84271&r2=84272
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Mon Oct  1 16:15:57 2007
@@ -547,6 +547,7 @@
 		const char *lock_name;
 		void *lock_addr;
 		int times_locked;
+		enum ast_lock_type type;
 		/*! This thread is waiting on this lock */
 		unsigned int pending:1;
 	} locks[AST_MAX_LOCKS];
@@ -592,8 +593,8 @@
  */
 AST_THREADSTORAGE_CUSTOM(thread_lock_info, NULL, lock_info_destroy);
 
-void ast_store_lock_info(const char *filename, int line_num, 
-	const char *func, const char *lock_name, void *lock_addr)
+void ast_store_lock_info(enum ast_lock_type type, const char *filename,
+	int line_num, const char *func, const char *lock_name, void *lock_addr)
 {
 	struct thr_lock_info *lock_info;
 	int i;
@@ -625,6 +626,7 @@
 	lock_info->locks[i].lock_name = lock_name;
 	lock_info->locks[i].lock_addr = lock_addr;
 	lock_info->locks[i].times_locked = 1;
+	lock_info->locks[i].type = type;
 	lock_info->locks[i].pending = 1;
 	lock_info->num_locks++;
 
@@ -679,6 +681,20 @@
 	lock_info->num_locks--;
 
 	pthread_mutex_unlock(&lock_info->lock);
+}
+
+static const char *locktype2str(enum ast_lock_type type)
+{
+	switch (type) {
+	case AST_MUTEX:
+		return "MUTEX";
+	case AST_RDLOCK:
+		return "RDLOCK";
+	case AST_WRLOCK:
+		return "WRLOCK";
+	}
+
+	return "UNKNOWN";
 }
 
 static char *handle_show_locks(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
@@ -713,9 +729,11 @@
 			lock_info->thread_name);
 		pthread_mutex_lock(&lock_info->lock);
 		for (i = 0; i < lock_info->num_locks; i++) {
-			ast_cli(a->fd, "=== ---> %sLock #%d: %s %d %s %s %p (%d)\n", 
+			ast_cli(a->fd, "=== ---> %sLock #%d (%s): %s %d %s %s %p (%d)\n", 
 				lock_info->locks[i].pending ? "Waiting for " : "", i,
-				lock_info->locks[i].file, lock_info->locks[i].line_num,
+				lock_info->locks[i].file, 
+				locktype2str(lock_info->locks[i].type),
+				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);




More information about the asterisk-commits mailing list