diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h
index f9a6a58311e6ee2f6c7fa4a1b23645d6c8998867..5d6ef43bba73045239ae02d1aae39f34776239ef 100644
--- a/include/asterisk/lock.h
+++ b/include/asterisk/lock.h
@@ -154,12 +154,12 @@ void ast_store_lock_info(enum ast_lock_type type, const char *filename,
 /*!
  * \brief Mark the last lock as acquired
  */
-void ast_mark_lock_acquired(void);
+void ast_mark_lock_acquired(void *lock_addr);
 
 /*!
  * \brief Mark the last lock as failed (trylock)
  */
-void ast_mark_lock_failed(void);
+void ast_mark_lock_failed(void *lock_addr);
 
 /*!
  * \brief remove lock info for the current thread
@@ -378,7 +378,7 @@ static inline int __ast_pthread_mutex_lock(const char *filename, int lineno, con
 		}
 		ast_reentrancy_unlock(t);
 		if (t->track)
-			ast_mark_lock_acquired();
+			ast_mark_lock_acquired(&t->mutex);
 	} else {
 		if (t->track)
 			ast_remove_lock_info(&t->mutex);
@@ -428,9 +428,9 @@ static inline int __ast_pthread_mutex_trylock(const char *filename, int lineno,
 		}
 		ast_reentrancy_unlock(t);
 		if (t->track)
-			ast_mark_lock_acquired();
+			ast_mark_lock_acquired(&t->mutex);
 	} else if (t->track) {
-		ast_mark_lock_failed();
+		ast_mark_lock_failed(&t->mutex);
 	}
 
 	return res;
@@ -917,7 +917,7 @@ static inline int _ast_rwlock_rdlock(ast_rwlock_t *lock, const char *name,
 	ast_store_lock_info(AST_RDLOCK, file, line, func, name, lock);
 	res = pthread_rwlock_rdlock(lock);
 	if (!res)
-		ast_mark_lock_acquired();
+		ast_mark_lock_acquired(lock);
 	else
 		ast_remove_lock_info(lock);
 	return res;
@@ -948,7 +948,7 @@ static inline int _ast_rwlock_wrlock(ast_rwlock_t *lock, const char *name,
 	ast_store_lock_info(AST_WRLOCK, file, line, func, name, lock);
 	res = pthread_rwlock_wrlock(lock);
 	if (!res)
-		ast_mark_lock_acquired();
+		ast_mark_lock_acquired(lock);
 	else
 		ast_remove_lock_info(lock);
 	return res;
@@ -979,7 +979,7 @@ static inline int _ast_rwlock_tryrdlock(ast_rwlock_t *lock, const char *name,
 	ast_store_lock_info(AST_RDLOCK, file, line, func, name, lock);
 	res = pthread_rwlock_tryrdlock(lock);
 	if (!res)
-		ast_mark_lock_acquired();
+		ast_mark_lock_acquired(lock);
 	else
 		ast_remove_lock_info(lock);
 	return res;
@@ -1010,7 +1010,7 @@ static inline int _ast_rwlock_trywrlock(ast_rwlock_t *lock, const char *name,
 	ast_store_lock_info(AST_WRLOCK, file, line, func, name, lock);
 	res = pthread_rwlock_trywrlock(lock);
 	if (!res)
-		ast_mark_lock_acquired();
+		ast_mark_lock_acquired(lock);
 	else
 		ast_remove_lock_info(lock);
 	return res;
diff --git a/main/utils.c b/main/utils.c
index fcdd527dd1011c5c5c7c63843b24d76be6dcee72..f8421b0c5329c90abba67431eba7aba40c9d028b 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -633,7 +633,7 @@ void ast_store_lock_info(enum ast_lock_type type, const char *filename,
 	pthread_mutex_unlock(&lock_info->lock);
 }
 
-void ast_mark_lock_acquired(void)
+void ast_mark_lock_acquired(void *lock_addr)
 {
 	struct thr_lock_info *lock_info;
 
@@ -641,11 +641,13 @@ void ast_mark_lock_acquired(void)
 		return;
 
 	pthread_mutex_lock(&lock_info->lock);
-	lock_info->locks[lock_info->num_locks - 1].pending = 0;
+	if (lock_info->locks[lock_info->num_locks - 1].lock_addr == lock_addr) {
+		lock_info->locks[lock_info->num_locks - 1].pending = 0;
+	}
 	pthread_mutex_unlock(&lock_info->lock);
 }
 
-void ast_mark_lock_failed(void)
+void ast_mark_lock_failed(void *lock_addr)
 {
 	struct thr_lock_info *lock_info;
 
@@ -653,8 +655,10 @@ void ast_mark_lock_failed(void)
 		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--;
+	if (lock_info->locks[lock_info->num_locks - 1].lock_addr == lock_addr) {
+		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);
 }
 
diff --git a/utils/check_expr.c b/utils/check_expr.c
index 00d00d802a18e88e4df350e9e59a24e1dbabc76c..009fe86736d65bf563f85e05430bd3cbcced96da 100644
--- a/utils/check_expr.c
+++ b/utils/check_expr.c
@@ -93,8 +93,8 @@ void ast_store_lock_info(enum ast_lock_type type, const char *filename,
     /* not a lot to do in a standalone w/o threading! */
 }
 
-void ast_mark_lock_acquired(void);
-void ast_mark_lock_acquired(void)
+void ast_mark_lock_acquired(void *);
+void ast_mark_lock_acquired(void *foo)
 {
     /* not a lot to do in a standalone w/o threading! */
 }