[asterisk-commits] russell: branch russell/debug_threads r77873 - in /team/russell/debug_threads...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Aug 1 13:35:19 CDT 2007
Author: russell
Date: Wed Aug 1 13:35:18 2007
New Revision: 77873
URL: http://svn.digium.com/view/asterisk?view=rev&rev=77873
Log:
Take into account that when a thread is sleeping in cond_wait, that it has
released the associated mutex
Modified:
team/russell/debug_threads/include/asterisk/lock.h
team/russell/debug_threads/utils.c
Modified: team/russell/debug_threads/include/asterisk/lock.h
URL: http://svn.digium.com/view/asterisk/team/russell/debug_threads/include/asterisk/lock.h?view=diff&rev=77873&r1=77872&r2=77873
==============================================================================
--- team/russell/debug_threads/include/asterisk/lock.h (original)
+++ team/russell/debug_threads/include/asterisk/lock.h Wed Aug 1 13:35:18 2007
@@ -440,6 +440,7 @@
t->thread[t->reentrancy] = 0;
}
+ ast_remove_lock_info(&t->mutex);
if ((res = pthread_cond_wait(cond, &t->mutex))) {
__ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",
filename, lineno, func, strerror(res));
@@ -447,6 +448,7 @@
DO_THREAD_CRASH;
#endif
} else {
+ ast_store_lock_info(filename, lineno, func, mutex_name, &t->mutex);
if (t->reentrancy < AST_MAX_REENTRANCY) {
t->file[t->reentrancy] = filename;
t->lineno[t->reentrancy] = lineno;
@@ -503,6 +505,7 @@
t->thread[t->reentrancy] = 0;
}
+ ast_remove_lock_info(&t->mutex);
if ((res = pthread_cond_timedwait(cond, &t->mutex, abstime)) && (res != ETIMEDOUT)) {
__ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",
filename, lineno, func, strerror(res));
@@ -510,6 +513,7 @@
DO_THREAD_CRASH;
#endif
} else {
+ ast_store_lock_info(filename, lineno, func, mutex_name, &t->mutex);
if (t->reentrancy < AST_MAX_REENTRANCY) {
t->file[t->reentrancy] = filename;
t->lineno[t->reentrancy] = lineno;
Modified: team/russell/debug_threads/utils.c
URL: http://svn.digium.com/view/asterisk/team/russell/debug_threads/utils.c?view=diff&rev=77873&r1=77872&r2=77873
==============================================================================
--- team/russell/debug_threads/utils.c (original)
+++ team/russell/debug_threads/utils.c Wed Aug 1 13:35:18 2007
@@ -64,6 +64,11 @@
static char base64[64];
static char b2a[256];
+
+AST_MUTEX_DEFINE_STATIC(fetchadd_m); /* used for all fetc&add ops */
+
+AST_MUTEX_DEFINE_STATIC(lock1);
+AST_MUTEX_DEFINE_STATIC(lock2);
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined(__APPLE__) || defined(__CYGWIN__)
@@ -1214,8 +1219,6 @@
#endif
}
-AST_MUTEX_DEFINE_STATIC(fetchadd_m); /* used for all fetc&add ops */
-
int ast_atomic_fetchadd_int_slow(volatile int *p, int v)
{
int ret;
@@ -1226,12 +1229,37 @@
return ret;
}
+static void *lock_test1(void *data)
+{
+ ast_mutex_lock(&lock1);
+ usleep(3000000);
+ ast_mutex_lock(&lock2);
+
+ return NULL;
+}
+
+static void *lock_test2(void *data)
+{
+ ast_mutex_lock(&lock2);
+ usleep(3000000);
+ ast_mutex_lock(&lock1);
+
+ return NULL;
+}
+
int ast_utils_init(void)
{
+ pthread_t blah;
+
base64_init();
#ifdef DEBUG_THREADS
ast_cli_register_multiple(utils_cli, sizeof(utils_cli) / sizeof(utils_cli[0]));
#endif
+
+
+ ast_pthread_create(&blah, NULL, lock_test1, NULL);
+ ast_pthread_create(&blah, NULL, lock_test2, NULL);
+
return 0;
}
More information about the asterisk-commits
mailing list