]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix a bug in the lock tracking code that was discovered by mmichelson. The issue
authorRussell Bryant <russell@russellbryant.com>
Thu, 28 Feb 2008 22:23:05 +0000 (22:23 +0000)
committerRussell Bryant <russell@russellbryant.com>
Thu, 28 Feb 2008 22:23:05 +0000 (22:23 +0000)
is that if the lock history array was full, then the functions to mark a lock as
acquired or not would adjust the stats for whatever lock is at the end of the array,
which may not be itself.  So, do a sanity check to make sure that we're updating
lock info for the proper lock.

(This explains the bizarre stats on lock #63 in BE-396, thanks Mark!)

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@105116 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/lock.h
main/utils.c

index 2dcf9c4c82f1b374e768634b51778e2bed00f049..8a3ed1d5f434dda3ad33f34bf4799593c7b966bd 100644 (file)
@@ -147,12 +147,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
@@ -371,7 +371,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);
@@ -421,9 +421,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;
@@ -900,7 +900,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;
@@ -933,7 +933,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;
@@ -966,7 +966,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;
@@ -999,7 +999,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;
index f309d87a13182199b53f4b9ae394ba807eaae96d..755789c7211e3a3b6463ff3ff0418ade1f4496fa 100644 (file)
@@ -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);
 }