aboutsummaryrefslogtreecommitdiffstats
path: root/include/asterisk/lock.h
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-10-06 04:30:16 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-10-06 04:30:16 +0000
commitdab68332f3e2d8612afb71bbe3c6c77ee88474c4 (patch)
treead75019c4a2578b2e611928f3777b7607b49147b /include/asterisk/lock.h
parent6397b378376611b1c76f484a6fa75b9b6103fdc4 (diff)
Locking updates for debug mode, fix SIP MWI (bug #2582)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3918 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include/asterisk/lock.h')
-rwxr-xr-xinclude/asterisk/lock.h25
1 files changed, 18 insertions, 7 deletions
diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h
index 059bc89c6..7d2807d85 100755
--- a/include/asterisk/lock.h
+++ b/include/asterisk/lock.h
@@ -3,9 +3,9 @@
*
* General Asterisk channel definitions.
*
- * Copyright (C) 1999, Mark Spencer
+ * Copyright (C) 1999-2004, Digium, Inc.
*
- * Mark Spencer <markster@linux-support.net>
+ * Mark Spencer <markster@digium.com>
*
* This program is free software, distributed under the terms of
* the GNU General Public License
@@ -65,6 +65,7 @@ struct ast_mutex_info {
pthread_mutex_t mutex;
char *file;
int lineno;
+ int reentrancy;
char *func;
pthread_t thread;
};
@@ -91,6 +92,7 @@ static inline int __ast_pthread_mutex_init_attr(char *filename, int lineno, char
t->lineno = lineno;
t->func = func;
t->thread = 0;
+ t->reentrancy = 0;
return pthread_mutex_init(&t->mutex, attr);
}
@@ -210,6 +212,7 @@ static inline int __ast_pthread_mutex_lock(char *filename, int lineno, char *fun
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 @@ static inline int __ast_pthread_mutex_trylock(char *filename, int lineno, char *
#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 @@ static inline int __ast_pthread_mutex_unlock(char *filename, int lineno, char *f
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",