[asterisk-commits] russell: branch russell/debug_threads r77826 - /team/russell/debug_threads/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 31 10:43:59 CDT 2007


Author: russell
Date: Tue Jul 31 10:43:59 2007
New Revision: 77826

URL: http://svn.digium.com/view/asterisk?view=rev&rev=77826
Log:
Declare a lock info struct for keeping track of which locks a thread holds.
Create a thread local instance of it and store a reference to it on the stack
in the common entry function for all threads.

Modified:
    team/russell/debug_threads/Makefile
    team/russell/debug_threads/utils.c

Modified: team/russell/debug_threads/Makefile
URL: http://svn.digium.com/view/asterisk/team/russell/debug_threads/Makefile?view=diff&rev=77826&r1=77825&r2=77826
==============================================================================
--- team/russell/debug_threads/Makefile (original)
+++ team/russell/debug_threads/Makefile Tue Jul 31 10:43:59 2007
@@ -72,7 +72,7 @@
 #endif
 
 # Optional debugging parameters
-DEBUG_THREADS = #-DDUMP_SCHEDULER #-DDEBUG_SCHEDULER #-DDEBUG_THREADS #-DDO_CRASH #-DDETECT_DEADLOCKS
+DEBUG_THREADS = -DDEBUG_THREADS  #-DDUMP_SCHEDULER #-DDEBUG_SCHEDULER #-DDEBUG_THREADS #-DDO_CRASH #-DDETECT_DEADLOCKS
 
 # Uncomment next one to enable ast_frame tracing (for debugging)
 TRACE_FRAMES = #-DTRACE_FRAMES

Modified: team/russell/debug_threads/utils.c
URL: http://svn.digium.com/view/asterisk/team/russell/debug_threads/utils.c?view=diff&rev=77826&r1=77825&r2=77826
==============================================================================
--- team/russell/debug_threads/utils.c (original)
+++ team/russell/debug_threads/utils.c Tue Jul 31 10:43:59 2007
@@ -494,6 +494,31 @@
 	char *name;
 };
 
+#ifdef DEBUG_THREADS
+
+/*! \brief A reasonable maximum number of locks a thread would be holding ... */
+#define AST_MAX_LOCKS 16
+
+/*! \brief Keep track of which locks a thread holds */
+struct thr_lock_info {
+	pthread_t thread_id;
+	const char *file[AST_MAX_LOCKS];
+	int line_num[AST_MAX_LOCKS];
+	const char *func[AST_MAX_LOCKS];
+	unsigned int num_locks;
+};
+
+static void lock_info_destroy(void *data)
+{
+	struct thr_lock_info *lock_info = data;
+
+	free(lock_info);
+}
+
+AST_THREADSTORAGE_CUSTOM(thread_lock_info, NULL, lock_info_destroy);
+
+#endif /* DEBUG_THREADS */
+
 /*
  * on OS/X, pthread_cleanup_push() and pthread_cleanup_pop()
  * are odd macros which start and end a block, so they _must_ be
@@ -505,6 +530,7 @@
 {
 	void *ret;
 	struct thr_arg a = *((struct thr_arg *) data);	/* make a local copy */
+	struct thr_lock_info *lock_info;
 
 	/* note that even though data->name is a pointer to allocated memory,
 	   we are not freeing it here because ast_register_thread is going to
@@ -514,7 +540,17 @@
 	free(data);
 	ast_register_thread(a.name);
 	pthread_cleanup_push(ast_unregister_thread, (void *) pthread_self());
+
+#ifdef DEBUG_THREADS
+	if (!(lock_info = ast_threadstorage_get(&thread_lock_info, sizeof(*lock_info))))
+		return NULL;
+
+	lock_info->thread_id = pthread_self();
+
+#endif /* DEBUG_THREADS */
+
 	ret = a.start_routine(a.data);
+
 	pthread_cleanup_pop(1);
 
 	return ret;




More information about the asterisk-commits mailing list