[Asterisk-cvs] asterisk/include/asterisk lock.h,1.23,1.24

markster at lists.digium.com markster at lists.digium.com
Wed Oct 6 00:28:48 CDT 2004


Update of /usr/cvsroot/asterisk/include/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv7837/include/asterisk

Modified Files:
	lock.h 
Log Message:
Locking updates for debug mode, fix SIP MWI (bug #2582)


Index: lock.h
===================================================================
RCS file: /usr/cvsroot/asterisk/include/asterisk/lock.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- lock.h	8 Aug 2004 17:15:02 -0000	1.23
+++ lock.h	6 Oct 2004 04:30:16 -0000	1.24
@@ -3,9 +3,9 @@
  *
  * General Asterisk channel definitions.
  * 
- * Copyright (C) 1999, Mark Spencer
+ * Copyright (C) 1999-2004, Digium, Inc.
  *
- * Mark Spencer <markster at linux-support.net>
+ * Mark Spencer <markster at digium.com>
  *
  * This program is free software, distributed under the terms of
  * the GNU General Public License
@@ -65,6 +65,7 @@
 	pthread_mutex_t mutex;
 	char *file;
 	int lineno;
+	int reentrancy;
 	char *func;
 	pthread_t thread;
 };
@@ -91,6 +92,7 @@
 	t->lineno = lineno;
 	t->func = func;
 	t->thread  = 0;
+	t->reentrancy = 0;
 	return pthread_mutex_init(&t->mutex, attr);
 }
 
@@ -210,6 +212,7 @@
 	res = pthread_mutex_lock(&t->mutex);
 #endif /*  DETECT_DEADLOCKS */
 	if (!res) {
+		t->reentrancy++;
 		t->file = filename;
 		t->lineno = lineno;
 		t->func = func;
@@ -241,6 +244,7 @@
 #endif /* definded(AST_MUTEX_INIT_W_CONSTRUCTORS) || defined(AST_MUTEX_INIT_ON_FIRST_USE) */
 	res = pthread_mutex_trylock(&t->mutex);
 	if (!res) {
+		t->reentrancy++;
 		t->file = filename;
 		t->lineno = lineno;
 		t->func = func;
@@ -260,11 +264,18 @@
 			filename, lineno, func, mutex_name);
 	}
 #endif
-	/* Assumes lock is actually held */
-	t->file = NULL;
-	t->lineno = 0;
-	t->func = NULL;
-	t->thread = 0;
+	--t->reentrancy;
+	if (t->reentrancy < 0) {
+		fprintf(stderr, "%s line %d (%s): Freed more times than we've locked!\n",
+			filename, lineno, func, mutex_name);
+		t->reentrancy = 0;
+	}
+	if (!t->rentrancy) {
+		t->file = NULL;
+		t->lineno = 0;
+		t->func = NULL;
+		t->thread = 0;
+	}
 	res = pthread_mutex_unlock(&t->mutex);
 	if (res) {
 		fprintf(stderr, "%s line %d (%s): Error releasing mutex: %s\n", 




More information about the svn-commits mailing list