aboutsummaryrefslogtreecommitdiffstats
path: root/main/utils.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-10-09 21:55:06 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-10-09 21:55:06 +0000
commita8e66dc137a198d1d429c2129ef630bee848a820 (patch)
tree75f56f11bcfbb63b11fa03eb407cf5e75404694b /main/utils.c
parent32f9ef55236ee53de4ec3ad1f6a210658f254bbb (diff)
This commit fixes the following issues:
- Deadlock in ast_write (issue #10406) - Deadlock in ast_read (issue #10406) - Possible mutex initialization error in lock.h (issue #10571) git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@85158 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/utils.c')
-rw-r--r--main/utils.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/main/utils.c b/main/utils.c
index e6b33fb1d..ebf80ebb9 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -540,7 +540,7 @@ struct thr_lock_info {
int times_locked;
enum ast_lock_type type;
/*! This thread is waiting on this lock */
- unsigned int pending:1;
+ int pending:2;
} locks[AST_MAX_LOCKS];
/*! This is the number of locks currently held by this thread.
* The index (num_locks - 1) has the info on the last one in the
@@ -636,6 +636,19 @@ void ast_mark_lock_acquired(void)
pthread_mutex_unlock(&lock_info->lock);
}
+void ast_mark_lock_failed(void)
+{
+ struct thr_lock_info *lock_info;
+
+ if (!(lock_info = ast_threadstorage_get(&thread_lock_info, sizeof(*lock_info))))
+ return;
+
+ pthread_mutex_lock(&lock_info->lock);
+ lock_info->locks[lock_info->num_locks - 1].pending = -1;
+ lock_info->locks[lock_info->num_locks - 1].times_locked--;
+ pthread_mutex_unlock(&lock_info->lock);
+}
+
void ast_remove_lock_info(void *lock_addr)
{
struct thr_lock_info *lock_info;
@@ -708,7 +721,7 @@ static int handle_show_locks(int fd, int argc, char *argv[])
pthread_mutex_lock(&lock_info->lock);
for (i = 0; i < lock_info->num_locks; i++) {
ast_cli(fd, "=== ---> %sLock #%d (%s): %s %d %s %s %p (%d)\n",
- lock_info->locks[i].pending ? "Waiting for " : "", i,
+ lock_info->locks[i].pending > 0 ? "Waiting for " : lock_info->locks[i].pending < 0 ? "Tried and failed to get " : "", i,
lock_info->locks[i].file,
locktype2str(lock_info->locks[i].type),
lock_info->locks[i].line_num,